-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add docs for Server.terminate event #7790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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>`__ | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can just update the example to pull from the container: |
||
|
|
||
| .. versionadded:: 5.1.0 | ||
|
|
||
| Common Mistakes with Immutable Responses | ||
| ======================================== | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.