Skip to content

HTTP client: Support passing default request headers #449

Closed

Description

@clue

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?

Activity

  1. WyriHaximus commented on Apr 11, 2022

    @WyriHaximus
    Member

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

  2. bartvanhoutte commented on May 24, 2022

    @bartvanhoutte

    👋 Unsetting a default header, would that happen through

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

    or

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

    What do you think?

  3. clue commented on May 24, 2022

    @clue
    MemberAuthor

    👋 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 👍

  4. added this to the v1.8.0 milestone on Aug 26, 2022
  5. clue commented on Sep 15, 2022

    @clue
    MemberAuthor

    Closed via #461 :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions