HTTP client: Support passing default request headers
Here's what this could potentially look like:
$browser = new React\Http\Browser();
$browser = $browser->withProtocolVersion('1.1'); // already supported
$browser = $browser->withHeader('User-Agent', 'ACME'); // could be useful?
$browser->get($url)->then(…);
This isn't currently supported, but seems reasonable and would also allow other packages to take advantage of custom HTTP request headers. What do you think about this?
Seeing this pattern in my own projects where I do this for the Authorization header. So lets add this 👍
👋 Unsetting a default header, would that happen through
$browser = $browser->withHeader('User-Agent', null);
or
$browser = $browser->withoutHeader('User-Agent')
What do you think?
:wave: Unsetting a default header, would that happen through […]
$browser = $browser->withoutHeader('User-Agent')
@bartvanhoutte The idea is definitely to keep this in line with our existing interfaces. In particular, PSR-7 (HTTP messages) already define a withoutHeader() method, so I would absolutely go for this as well here :+1:
Closed via #461 :shipit: