-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[8.x] Add Http::configure()
method
#40332
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
[8.x] Add Http::configure()
method
#40332
Conversation
Does it make sense for this to be invoked right before the request is actually sent? That way you could inspect other information about the request before configuring it further - for example, what if you only wanted to add some headers if the URI matched a given value? |
@taylorotwell Yeah, fair point. My personal use case was for all requests, regardless of URL but you're right, that would make a lot more sense. It's getting late here so I'll update this tomorrow if that's okay? |
OK |
@taylorotwell I've updated the logic to configure the request at the top of the |
Hmm - I dunno, something about this still seems kinda clunky to use. How do I inspect the request for a header or look at its final URI? How can I see what data it has? |
Happy to close this and leave it be if you think it's not worth it. There are user-land workarounds like constructing a base client that has the correct options already. Without dedicated methods on the request object to inspect the Guzzle options, there's no easy way to do the things you mentioned. |
Yeah - here's how I would do this: In service provider: Http::macro('github', function () {
return Http::withHeaders([
'X-First' => 'foo',
])->baseUrl('https://github.com');
}); In code: Http::github()->get('/'); May document this 🤔 |
@taylorotwell Yeah, this is an alternative approach. Thanks for taking a look though! :) I guess the only drawback here is that lack of autocomplete/intellisense, but easily fixed with ide-helper or a stubs file. |
Embrace the dynamic language ❤️ |
🔥🔥🔥 |
Rad! |
This pull request introduces a new
Http::configure()
method that can be used to modify allPendingRequest
objects globally.In this scenario, all requests made from the app will have this custom header applied.