40 protected AjaxService $ajax,
44 $this->headers =
new ResponseHeaderBag();
57 $this->headers->set($name, $value, $replace);
70 if (!$this->events->trigger(
'init:cookie', $cookie->name, $cookie)) {
74 $symfony_cookie =
new Cookie(
84 $this->headers->setCookie($symfony_cookie);
95 public function getHeaders(
bool $remove_existing =
true): ResponseHeaderBag {
98 $headers_list = headers_list();
99 foreach ($headers_list as
$header) {
100 if (stripos($header,
'HTTP/1.1') !==
false) {
106 if ($remove_existing) {
107 header_remove(
$name);
125 $header_bag->add($headers);
129 return $response->prepare($this->request);
143 $header_bag->add($headers);
147 return $response->prepare($this->request);
161 $header_bag->add($headers);
169 $header_bag->remove(
'Content-Type');
173 return $response->prepare($this->request);
184 if (isset($this->response_sent)) {
185 if ($this->response_sent !== $response) {
186 $this->
getLogger()->error(
'Unable to send the following response: ' . PHP_EOL
187 . (
string) $response . PHP_EOL
188 .
'because another response has already been sent: ' . PHP_EOL
189 . (
string) $this->response_sent);
192 if (!$this->events->triggerBefore(
'send',
'http_response', $response)) {
197 $method =
$request->getRealMethod() ?:
'GET';
200 $this->
getLogger()->notice(
"Responding to {$method} {$path}");
201 if (!$this->transport->send($response)) {
205 $this->events->triggerAfter(
'send',
'http_response', $response);
235 $response = $this->events->triggerResults(
'response', $response_type, [], $response);
237 throw new UnexpectedValueException(
"Handlers for 'response', '{$response_type}' event must return an instanceof " . ResponseBuilder::class);
246 $headers[
'X-Content-Type-Options'] =
'nosniff';
249 $is_xhr = $this->request->isXmlHttpRequest();
259 $response->
setForwardURL((
string) $this->request->headers->get(
'Referer'));
270 if ($is_xhr && ($is_action || $this->ajax->isAjax2Request())) {
273 $headers[
'Content-Type'] =
'application/json; charset=UTF-8';
276 if ($response->
isOk()) {
286 if ($this->ajax->isReady() && $response->
isSuccessful()) {
309 if ($this->ajax->isReady()) {
310 return $this->
send($this->ajax->respondWithError(
$error, $status_code));
313 if ($this->
isXhr()) {
326 'current_url' => $this->request->getCurrentURL(),
332 $forward_reason = (string) $status_code;
336 if (isset($this->response_sent)) {
342 $params[
'type'] = $forward_reason;
367 if ($this->ajax->isReady()) {
368 return $this->
send($this->ajax->respondFromOutput(
$content, $this->parseContext()));
390 'value' => $this->ajax->decodeJson(
$content),
391 'current_url' => $this->request->getCurrentURL(),
416 'current_url' => $this->request->getCurrentURL(),
421 $forward_reason = (string) $status_code;
425 if (isset($this->response_sent)) {
437 switch ($status_code) {
445 case 'walled_garden':
447 $status_code = (int) $status_code;
448 if (!$status_code || $status_code < 100 || $status_code > 599) {
454 if ($this->
isXhr()) {
455 if ($status_code < 100 || ($status_code >= 300 && $status_code <= 399) || $status_code > 599) {
466 $headers[
'Content-Type'] =
'application/json; charset=UTF-8';
473 if (!is_int($status_code) || $status_code < 300 || $status_code > 399) {
492 $segments = $this->request->getUrlSegments();
495 switch ($identifier) {
498 if (
$page ===
'view') {
500 return "view:{$view}";
503 return "form:{$form}";
511 return "action:{$action}";
516 return "path:{$path}";
525 return $this->request->isXmlHttpRequest();
534 return str_starts_with($this->
parseContext(),
'action:');
616 if (!
preg_match(
'/^(http|https|ftp|sftp|ftps):\/\//', $url)) {
ResponseTransport $transport
makeSecureForwardUrl(string $url)
Ensure the url has a valid protocol for browser use.
HTTP response builder interface.
respondWithError(ResponseBuilder $response)
Send error HTTP response.
getStatusCode()
Returns status code.
$params
Saves global plugin settings.
elgg_normalize_site_url(string $unsafe_url)
From untrusted input, get a site URL safe for forwarding.
isRedirection()
Check if response is redirection.
setCookie(\ElggCookie $cookie)
Set a cookie, but allow plugins to customize it first.
getContent()
Returns response body.
if(!$user||!$user->canDelete()) $name
send(SymfonyResponse $response)
Send a response.
isAction()
Check if the requested path is an action.
prepareResponse(?string $content= '', int $status=200, array $headers=[])
Creates an HTTP response.
elgg_get_session()
Gets Elgg's session object.
isNotModified()
Check if response has been modified.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
stringify($content= '')
Stringify/serialize response data.
__construct(protected Request $request, protected AjaxService $ajax, protected EventsService $events)
Constructor.
isOk()
Check if response is OK.
ResponseHeaderBag $headers
setHeader(string $name, string $value, bool $replace=true)
Sets headers to apply to all responses being sent.
getSentResponse()
Returns a response that was sent to the client.
Models the Ajax API service.
elgg_view_resource(string $name, array $vars=[])
Render a resource view.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
HTTP response transport interface.
trait Loggable
Enables adding a logger.
isServerError()
Check if response is server error.
const REFERRER
Used in calls to forward() to specify the browser should be redirected to the referring page...
redirect(string $forward_url=REFERRER, $status_code=ELGG_HTTP_FOUND)
Prepares a redirect response.
static getResponseTransport()
Build a transport for sending responses.
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
Exception thrown if a value does not match with a set of values.
wrapAjaxResponse($content= '', string $forward_url=null)
Wraps response content in an Ajax2 compatible format.
setTransport(ResponseTransport $transport)
Replaces response transport.
isXhr()
Check if the request is an XmlHttpRequest.
const ELGG_JSON_ENCODING
Default JSON encoding.
getHeaders(bool $remove_existing=true)
Get headers set to apply to all responses.
isSuccessful()
Check if response is successful.
if(!$entity->delete(true, true)) $forward_url
respondFromContent(ResponseBuilder $response)
Send OK response.
setForwardURL(string $forward_url=REFERRER)
Sets redirect URL.
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
getSiteRefererUrl()
Ensures the referer header is a site url.
Redirect response builder.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
const ELGG_HTTP_NOT_MODIFIED
if(isset($_COOKIE['elggperm'])) $session
getLogger()
Returns logger.
setStatusCode(int $status_code)
Sets response HTTP status code.
isClientError()
Check if response is client error.
foreach($periods as $period) $header
getException()
Get the exception for this reponse.
$content
Set robots.txt action.
parseContext()
Parses response type to be used as event type.
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
prepareRedirectResponse(string $url, int $status=302, array $headers=[])
Creates a redirect response.
setHeaders(array $headers=[])
Sets additional response headers.
const ELGG_HTTP_SEE_OTHER
setContent($content= '')
Sets response body.
getHeaders()
Returns additional response headers.
elgg_normalize_url(string $url)
respond(ResponseBuilder $response)
Send HTTP response.
closeSession()
Closes the session.
elgg_view_exists(string $view, string $viewtype= '', bool $recurse=true)
Returns whether the specified view exists.
normalize($content= '')
Normalizes content into serializable data by walking through arrays and objectifying Elgg entities...
getForwardURL()
Returns redirect URL.
prepareJsonResponse($content= '', int $status=200, array $headers=[])
Creates an JSON response.
SymfonyResponse $response_sent