50 $this->headers =
new ResponseHeaderBag();
63 $this->headers->set($name, $value, $replace);
76 if (!$this->events->trigger(
'init:cookie', $cookie->name, $cookie)) {
80 $symfony_cookie =
new Cookie(
90 $this->headers->setCookie($symfony_cookie);
101 public function getHeaders(
bool $remove_existing =
true): ResponseHeaderBag {
104 $headers_list = headers_list();
105 foreach ($headers_list as
$header) {
106 if (stripos($header,
'HTTP/1.1') !==
false) {
112 if ($remove_existing) {
113 header_remove(
$name);
131 $header_bag->add($headers);
135 return $response->prepare($this->request);
149 $header_bag->add($headers);
153 return $response->prepare($this->request);
167 $header_bag->add($headers);
175 $header_bag->remove(
'Content-Type');
179 return $response->prepare($this->request);
190 if (isset($this->response_sent)) {
191 if ($this->response_sent !== $response) {
192 $this->
getLogger()->error(
'Unable to send the following response: ' . PHP_EOL
193 . (
string) $response . PHP_EOL
194 .
'because another response has already been sent: ' . PHP_EOL
195 . (
string) $this->response_sent);
198 if (!$this->events->triggerBefore(
'send',
'http_response', $response)) {
203 $method = $request->getRealMethod() ?:
'GET';
206 $this->
getLogger()->notice(
"Responding to {$method} {$path}");
207 if (!$this->transport->send($response)) {
211 $this->events->triggerAfter(
'send',
'http_response', $response);
241 $response = $this->events->triggerResults(
'response', $response_type, [], $response);
243 throw new UnexpectedValueException(
"Handlers for 'response', '{$response_type}' event must return an instanceof " . ResponseBuilder::class);
252 $headers[
'X-Content-Type-Options'] =
'nosniff';
255 $is_xhr = $this->request->isXmlHttpRequest();
265 $response->
setForwardURL((
string) $this->request->headers->get(
'Referer'));
276 if ($is_xhr && ($is_action || $this->ajax->isAjax2Request())) {
279 $headers[
'Content-Type'] =
'application/json; charset=UTF-8';
282 if ($response->
isOk()) {
292 if ($this->ajax->isReady() && $response->
isSuccessful()) {
315 if ($this->ajax->isReady()) {
316 return $this->
send($this->ajax->respondWithError(
$error, $status_code));
319 if ($this->
isXhr()) {
332 'current_url' => $this->request->getCurrentURL(),
338 $forward_reason = (string) $status_code;
342 if (isset($this->response_sent)) {
348 $params[
'type'] = $forward_reason;
373 if ($this->ajax->isReady()) {
374 return $this->
send($this->ajax->respondFromOutput(
$content, $this->parseContext()));
396 'value' => $this->ajax->decodeJson(
$content),
397 'current_url' => $this->request->getCurrentURL(),
422 'current_url' => $this->request->getCurrentURL(),
427 $forward_reason = (string) $status_code;
431 if (isset($this->response_sent)) {
443 switch ($status_code) {
451 case 'walled_garden':
453 $status_code = (int) $status_code;
454 if (!$status_code || $status_code < 100 || $status_code > 599) {
460 if ($this->
isXhr()) {
461 if ($status_code < 100 || ($status_code >= 300 && $status_code <= 399) || $status_code > 599) {
472 $headers[
'Content-Type'] =
'application/json; charset=UTF-8';
479 if (!is_int($status_code) || $status_code < 300 || $status_code > 399) {
498 $segments = $this->request->getUrlSegments();
501 switch ($identifier) {
504 if (
$page ===
'view') {
506 return "view:{$view}";
509 return "form:{$form}";
517 return "action:{$action}";
522 return "path:{$path}";
531 return $this->request->isXmlHttpRequest();
540 return str_starts_with($this->
parseContext(),
'action:');
622 if (!
preg_match(
'/^(http|https|ftp|sftp|ftps):\/\//', $url)) {
ResponseTransport $transport
makeSecureForwardUrl(string $url)
Ensure the url has a valid protocol for browser use.
getElggPath()
Get the Request URI minus querystring.
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.
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.
__construct(Request $request, AjaxService $ajax, EventsService $events)
Constructor.
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 "/".
if(!$entity->delete()) $forward_url
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