http icon indicating copy to clipboard operation
http copied to clipboard

Support for default request headers

Open 51imyyy opened this issue 3 years ago • 6 comments

closes issue: #449 new methods for the class Browser (withHeader and withoutHeader)

With this methods you are able to set/remove default headers

51imyyy avatar Jun 24 '22 19:06 51imyyy

Thank you @nhedger for your help :)

51imyyy avatar Jun 24 '22 19:06 51imyyy

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 avatar Aug 03 '22 23:08 frosty00

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

clue avatar Aug 05 '22 18:08 clue

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?

dinooo13 avatar Aug 12 '22 21:08 dinooo13

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?

yeah this looks like the correct solution

frosty00 avatar Aug 12 '22 23:08 frosty00

added the suggestion and squashed the commits. Now you can use the withoutHeader() to remove the default header "User-Agent"

51imyyy avatar Aug 13 '22 17:08 51imyyy

applied the suggestions.

I just added a missing opining tag (```php) to the README.md

51imyyy avatar Aug 30 '22 11:08 51imyyy

@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 avatar Sep 01 '22 07:09 SimonFrings

@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?

51imyyy avatar Sep 01 '22 08:09 51imyyy

So the real intention was only to change var_dump($response->getHeaders()); to var_dump($response); right

@51imyy Yep, I messed my suggestion up.

SimonFrings avatar Sep 01 '22 09:09 SimonFrings

@SimonFrings Changed it

51imyyy avatar Sep 01 '22 09:09 51imyyy

appiled the suggestions.

51imyyy avatar Sep 01 '22 09:09 51imyyy

Thank you :)

51imyyy avatar Sep 01 '22 14:09 51imyyy