Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions en/appendices/5-1-upgrade-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Http
- ``Client`` now emits ``HttpClient.beforeSend`` and ``HttpClient.afterSend``
events when requests are sent. You can use these events to perform logging,
caching or collect telemetry.
- ``Http\Server::terminate()`` was added. This method triggers the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we need to mention that this isn't automatically called and point to the other section you added.

``Server.terminate`` event which can be used to run logic after the response
has been sent in fastcgi environments. In other environments the
``Server.terminate`` event runs *before* the response has been sent.

TestSuite
---------
Expand Down
23 changes: 22 additions & 1 deletion en/controllers/request-response.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ will make the browser remove its local cookie::
.. _cors-headers:

Setting Cross Origin Request Headers (CORS)
===========================================
-------------------------------------------

The ``cors()`` method is used to define `HTTP Access Control
<https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS>`__
Expand All @@ -1067,6 +1067,27 @@ criteria are met:
is very application specific. We recommend you build your own ``CORSMiddleware``
if you need one and adjust the response object as desired.

Running logic after the Response has been sent
----------------------------------------------

In fastcgi based environments you can listen to the ``Server.terminate`` event
to run logic **after** the response has been sent to the client. Make sure your
application's **webroot/index.php** contains the following::
Comment on lines +1074 to +1075
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't write an exact replacement, but think we need to spell out that the changes must be added around the existing emit() call.

New applications created from the app template will include this.


$app = new Application(dirname(__DIR__) . '/config'))
$server = new Server($app);

$response = $server->run(ServerRequest::fromGlobals());
$server->emit($response);
$request = $app->getContainer()->get(ServerRequest::class);
$server->terminate($request, $response);

.. warning::
In non fastcgi environments the ``Server.terminate`` event is fired before
the response is sent.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add a warning about the scope of the request object used unless we want to make the modification suggested here: cakephp/cakephp#17514 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just update the example to pull from the container:
cakephp/cakephp#17514 (comment)


.. versionadded:: 5.1.0

Common Mistakes with Immutable Responses
========================================

Expand Down