Support for default request headers
closes issue: #449 new methods for the class Browser (withHeader and withoutHeader)
With this methods you are able to set/remove default headers
Thank you @nhedger for your help :)
I am getting banned from cloudflare for having the default user agent in this library. Is it possible to remove that header from here -https://github.com/reactphp/http/blob/b3ff9c8cf63c06b5b734a9ffe9e0e5586049e541/src/Client/RequestData.php#L32 and make it optional. I think that withoutHeaders will only apply to the headers that are added using withHeader. Can we make it so that withoutHeader can remove the User-Agent specified in mergeRequestHeaders too.
@frosty00 Good catch! Agree that it should be possible to remove the default User-Agent: ReactPHP/1 request header with a withoutHeader('User-Agent') call.
@51imyy Good job with the PR so far! Is this something you can look into as part of this PR? :+1:
How about removing the default User Agent from here:
https://github.com/reactphp/http/blob/b5a66a4faa77f8e8ab0094566501b9f40cb5079e/src/Client/RequestData.php#L32
and re-adding it in the Browser constructor via your new withHeader() function? Then it should be easily removable with withoutHeader(). What do you think about this?
How about removing the default User Agent from here:
https://github.com/reactphp/http/blob/b5a66a4faa77f8e8ab0094566501b9f40cb5079e/src/Client/RequestData.php#L32
and re-adding it in the Browser constructor via your new
withHeader()function? Then it should be easily removable withwithoutHeader(). What do you think about this?
yeah this looks like the correct solution
added the suggestion and squashed the commits. Now you can use the withoutHeader() to remove the default header "User-Agent"
applied the suggestions.
I just added a missing opining tag (```php) to the README.md
@51imyy I accidentally marked the first half of the examples (in README.md and docblocks) in my last review which now causes that half to be missing 😅
@SimonFrings I thought it was intended, so i applied it :sweat_smile: . I can change it back. So the real intention was only to change var_dump($response->getHeaders()); to var_dump($response); right?
So the real intention was only to change
var_dump($response->getHeaders());tovar_dump($response);right
@51imyy Yep, I messed my suggestion up.
@SimonFrings Changed it
appiled the suggestions.
Thank you :)