guzzle / guzzle

Guzzle, an extensible PHP HTTP client
https://docs.guzzlephp.org/
MIT License
23.15k stars 2.41k forks source link

Globally set or disable user agent string #2722

Closed rkuntoro closed 4 years ago

rkuntoro commented 4 years ago

Description The default user agent contains some sensitive information like the versions of Guzzle, CURL, and PHP. I would like to omit this or set my own user agent.

I can control the Guzzle user agent of my app (through header option), but there are lots of composer dependencies that is out of my control.

There should be an easy way to globally set the default user agent without maintaining a fork.

Example

function default_user_agent()
{
    if (defined('GUZZLE_DEFAULT_USER_AGENT')) {
        return GUZZLE_DEFAULT_USER_AGENT;
    }
   ...
gmponos commented 4 years ago

In Guzzle 7 we removed a lot of these sensitive info.

Furthermore you can set your own header on constructing the client

$client = new Client([
    'headers' => [ 'User-Agent' => ''],
]);
rkuntoro commented 4 years ago

@gmponos Thanks for the info.

I know that I can set my own header, but I just have no controls over what other libraries do that we include via composer. This is especially for many integration SDKs that sends requests using Guzzle.

Any chance this can get added to v6? Unfortunately we're not using PHP 7.2 yet.

GrahamCampbell commented 4 years ago

You should be able to pass a Guzzle client instance to the libraries you are using. If they don't support this, suggest they add it (and possibly send a PR to implement it).

GrahamCampbell commented 4 years ago

I think we didn't implement this user agent change on Guzzle 6 because we considered it to be a breaking change.

GrahamCampbell commented 4 years ago

Is there a library in particular you had in mind, that is doing this?

rkuntoro commented 4 years ago

A few that we use and dependencies of the libraries we included:

GrahamCampbell commented 4 years ago

https://github.com/php-http/guzzle6-adapter

You can certainly set the user agent header here. PSR requests let you do that.

rkuntoro commented 4 years ago

@GrahamCampbell Thanks. I closed the issue