Skip to content

Commit e399144

Browse files
committed
Minor reword
1 parent 3d45e5c commit e399144

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

components/browser_kit.rst

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,32 @@ provides access to the form properties (e.g. ``$form->getUri()``,
161161
// submit that form
162162
$crawler = $client->submit($form);
163163

164+
Custom Header Handling
165+
~~~~~~~~~~~~~~~~~~~~~~
166+
167+
.. versionadded:: 5.2
168+
169+
The ``getHeaders()`` method was introduced in Symfony 5.2.
170+
171+
The optional HTTP headers passed to the ``request()`` method follows the FastCGI
172+
request format (uppercase, underscores instead of dashes and prefixed with ``HTTP_``).
173+
Before saving those headers to the request, they are lower-cased, with ``HTTP_``
174+
stripped, and underscores turned to dashes.
175+
176+
If you're making a request to an application that has special rules about header
177+
capitalization or punctuation, override the ``getHeaders()`` method, which must
178+
return an associative array of headers::
179+
180+
protected function getHeaders(Request $request): array
181+
{
182+
$headers = parent::getHeaders($request);
183+
if (isset($request->getServer()['api_key'])) {
184+
$headers['api_key'] = $request->getServer()['api_key'];
185+
}
186+
187+
return $headers;
188+
}
189+
164190
Cookies
165191
-------
166192

@@ -310,30 +336,6 @@ dedicated web crawler or scraper such as `Goutte`_::
310336
$openPullRequests = trim($browser->clickLink('Pull requests')->filter(
311337
'.table-list-header-toggle a:nth-child(1)'
312338
)->text());
313-
314-
Dealing with Headers
315-
~~~~~~~~~~~~~~~~~~~~
316-
317-
The fifth parameter of `request()` accepts an array of headers in the same format
318-
you'd see in a FastCGI request: all-upper-case, dashes replaced with underscores,
319-
prefixed with `HTTP_`. Array keys are lower-cased, with `HTTP_` stripped, and
320-
underscores turned to dashes, before saving those headers to the request.
321-
322-
If you're making a request to an application that has special rules about header
323-
capitalization or punctuation, you'll want to override HttpBrowser's `getHeaders()`
324-
method, which takes a Request object and returns an asociative array of headers.
325-
For example::
326-
327-
protected function getHeaders(Request $request): array
328-
{
329-
$headers = parent::getHeaders($request);
330-
if (isset($request->getServer()['api_key'])) {
331-
$headers['api_key'] = $request->getServer()['api_key'];
332-
}
333-
return $headers;
334-
}
335-
336-
This override is available as of Symfony 5.2.
337339

338340
Learn more
339341
----------

0 commit comments

Comments
 (0)