File tree Expand file tree Collapse file tree
user_guide_src/source/libraries Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,7 +32,29 @@ as the second parameter of the ``setStatusCode()`` method::
3232Setting Headers
3333---------------
3434
35- TODO
35+ Often, you will need to set headers to be set for the response. The Response class makes this very simple to do,
36+ with the ``setHeader() `` method. The first parameter is the name of the header. The second parameter is the value,
37+ which can be either a string or an array of values that will be combined correctly when sent to the client.
38+ Using these functions instead of using the native PHP functions allows you to ensure that no headers are sent
39+ prematurely, causing errors, and makes testing possible.
40+ ::
41+
42+ $response->setHeader('Location', 'http://example.com')
43+ ->setHeader('WWW-Authenticate', 'Negotiate');
44+
45+ If the header exists and can have more than one value, you may use the ``appendHeader() `` and ``prependHeader() ``
46+ methods to add the value to the end or beginning of the values list, respectively. The first parameter is the name
47+ of the header, while the second is the value to append or prepend.
48+ ::
49+
50+ $response->setHeader('Cache-Control', 'no-cache')
51+ ->appendHeader('Cache-Control', 'must-revalidate');
52+
53+ Headers can be removed from the response with the ``removeHeader() `` method, which takes the header name as the only
54+ parameter. This is not case-sensitive.
55+ ::
56+
57+ $response->removeHeader('Location');
3658
3759HTTP Caching
3860============
You can’t perform that action at this time.
0 commit comments