Skip to content

Commit 8ba04d4

Browse files
committed
Documenting header methods in responses
1 parent 1d5403e commit 8ba04d4

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

user_guide_src/source/libraries/response.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,29 @@ as the second parameter of the ``setStatusCode()`` method::
3232
Setting 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

3759
HTTP Caching
3860
============

0 commit comments

Comments
 (0)