@@ -146,6 +146,46 @@ Filtering a POST variable would look like this::
146146All of the methods mentioned above support the filter type passed in as the last parameter, with the
147147exception of ``getJSON() ``.
148148
149+ Retrieving Headers
150+ ==================
151+
152+ You can get access to any header that was sent with the request with the ``getHeaders() `` method, which returns
153+ an array of all headers, with the key as the name of the header, and the value being an instance of
154+ ``CodeIgniter\HTTP\Header ``::
155+
156+ var_dump($request->getHeaders());
157+
158+ [
159+ 'Host' => CodeIgniter\HTTP\Header,
160+ 'Cache-Control' => CodeIgniter\HTTP\Header,
161+ 'Accept' => CodeIgniter\HTTP\Header,
162+ ]
163+
164+ If you only need a single header, you can pass the name into the ``getHeader() `` method. This will grab the
165+ specified header object in a case-insensitive manner if it exists. If not, then it will return ``null ``::
166+
167+ // these are all equivalent
168+ $host = $request->getHeader('host');
169+ $host = $request->getHeader('Host');
170+ $host = $request->getHeader('HOST');
171+
172+ You can always use ``hasHeader() `` to see if the header existed in this request::
173+
174+ if ($request->hasHeader('DNT'))
175+ {
176+ // Don't track something...
177+ }
178+
179+ If you need the value of header as a string with all values on one line, you can use the ``getHeaderLine() `` method::
180+
181+ // Accept-Encoding: gzip, deflate, sdch
182+ echo 'Accept-Encoding: '.$request->getHeaderLine('accept-encoding');
183+
184+ If you need the entire header, with the name and values in a single string, simply cast the header as a string::
185+
186+ echo (string)$header;
187+
188+
149189The Request URL
150190===============
151191
0 commit comments