-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client instantiation loses (default) config options #11
Comments
🤔 OK, the tests from https://github.com/php-http/client-integration-tests expect a request that gets a 30x response to actually get that response, which makes sense when you don't assume any default configuration of the underlying client. But as this is a guzzle adapter, I'd expect it to have the guzzle defaults. If it shouldn't use the guzzle defaults, there's still the problem that also explicitly passing a config doesn't work. |
Also just found that the implementation of PSR-18 Somehow it makes sense to me, as the PSR-7 response object doesn't have any option to get what uri was actually delivered (or also redirect steps in between). I just wondered as I previously didn't really find anything about redirects in the PSR-18 document. Just found something in the Meta document. I guess it just presumes that not automatically following redirects is standard. So does that mean, that every library supporting a PSR-18 http client has to implement redirects themselves? |
i just re-read our PSR-18, and notice that redirects are not explicitly mentioned. when we wrote the PSR, the intention was that the PSR-18 compliant client does not follow redirects (*). The important thing is that all clients behave the same way, otherwise you can't replace one client with another. Therefore it is by design that the guzzle adapter aims to have that behaviour. If you want to use PSR-18 and decided that you don't need to know about redirects: wrap the client in a plugin client and use the redirect plugin - that will then work with all clients, should you chose to switch from guzzle to something else. If you want to only use guzzle and have your application rely on guzzle behaviour, i would recommend to use it directly and not use the PSR-18 abstraction. I was not aware that guzzle client overwrites the options. I find that a bit unfortunate, because as you say, it makes
But this is in the guzzle repository, you would have to take that up with the maintainers there. (and changing it right away would not be possible as it would be quite the BC break) (*) Why not follow redirects: If you write an API client, you at least want to log a warning, or in test systems probably throw an error when getting redirected, because the overhead of doing every API call twice would be really bad. |
Thank you for the detailed answer!
I think only guzzle's own PSR-18 implementation, the |
async is not part of PSR-18, so that makes sense. there is also the @Nyholm wdyt about adapter |
With that i meant: both methods As mentioned I think the problem is how the guzzle client is built when using |
ah, so createWithConfig works as expected, when you use this adapter? |
we create the custom handler to not have the middlewares. would the correct overwriteable behaviour be to create the client without handler (so that the handler is autocreated as normal) but have default options for each default middleware to disable that middleware? is that how guzzle itself works when you would do but just as default options, overwriteable in createWithConfig? |
I'd say yes. At least I think that should work 👍🏻 |
@Nyholm do you have an opinion on this? my thinking is that we should copy the HandlerStack::create method (to be sure changes in guzzle do not throw us off) and set all four middleware options to false by default, so that they can be overwritten in createWithConfig. |
PHP version: 8.0.14
Description
When using the Client it happened that I got a 301 redirect response. So not the response from the uri where it redirected to but an actual response object with status code 301. The guzzle default should be to allow and automatically follow redirects and it also did then when I tried with guzzle directly.
I then also tried the
createWithConfig()
static method of the Client and explicitly gave it the config (allow_redirects as in the docs), but with the same outcome.How to reproduce
Make a Client and request a uri that redirects to somewhere else.
Possible Solution
The private static
buildClient()
method creates a handler stack and passes it along with the config over to the new guzzle client. When the guzzle client doesn't get a handler stack it creates one by callingHandlerStack::create()
. I think thebuildClient()
method should either use this method or even better, just don't create a handler stack itself but just leave this to guzzle itself?I'll prepare a PR for this.
The text was updated successfully, but these errors were encountered: