http icon indicating copy to clipboard operation
http copied to clipboard

HTTP client: Support passing default request headers

Open clue opened this issue 3 years ago • 3 comments

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?

clue avatar Apr 11 '22 11:04 clue

Seeing this pattern in my own projects where I do this for the Authorization header. So lets add this 👍

WyriHaximus avatar Apr 11 '22 12:04 WyriHaximus

👋 Unsetting a default header, would that happen through

$browser = $browser->withHeader('User-Agent', null);

or

$browser = $browser->withoutHeader('User-Agent')

What do you think?

bartvanhoutte avatar May 24 '22 15:05 bartvanhoutte

: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:

clue avatar May 24 '22 22:05 clue

Closed via #461 :shipit:

clue avatar Sep 15 '22 06:09 clue