Guzzle: Can RequestOptions get an entry for 'handler' in Guzzle 6?

Created on 6 Apr 2017  路  4Comments  路  Source: guzzle/guzzle

I'm using the following code to set up some default settings for my Guzzle client, and to set up a StackHandler:

// Create the HTTP client
$client = new Client([
    RequestOptions::COOKIES => true,
    RequestOptions::CONNECT_TIMEOUT => 10,
    RequestOptions::TIMEOUT => 10,
    RequestOptions::ALLOW_REDIRECTS => true,
    RequestOptions::PROXY => 'localhost:9001',
    'handler' => $stack,
]);

It feels a bit inconsistent not to have a RequestOptions::HANDLER or similar, and in any case I like constants, since it makes it more obvious if I add a typo. Was there a reason for not adding this const, and if not, can it be added?

kinquestion

All 4 comments

The handler is not a request option, but a client configuration: https://github.com/guzzle/guzzle/blob/a1c4a74bf31d4e41d783fafb635c806cc19c2e9b/src/Client.php#L45

I think it would be more confusing if we defined a RequestOption const for it.

Ah, fair enough @sagikazarmark. Would a const in the Client class be a good alternative?

Well, to be honest I don't feel the need for that, it's rather an overkill IMO. Mostly because I rarely construct the input array manually or even then I use the actual parameter names. If it's uncomfortable for you to configure them in one array, I would suggest moving the request options to a separate one and use array_merge to put them together.

No worries, I don't feel strongly about it. I just moderately prefer consts rather than literals, as it's easier to detect typos. Thanks for the reply.

Was this page helpful?
0 / 5 - 0 ratings