-
Notifications
You must be signed in to change notification settings - Fork 4
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
Apply global middleware also to Saloon requests #15
Conversation
Here's the Laravel PR: laravel/framework#48950 |
Oh wow, this is huge! Thank you so much @pascalbaljet for PR'ing a fix in the Laravel framework and Saloon 🤯 Will this introduce a breaking change in this library because of the minimum requirement of Laravel 10? Or could we remove the requirement for Laravel 9 and I could tag v2.1 of this library? I assume then Composer will automatically keep people on Laravel 9 using 2.0 and then anyone using >10 will go up to your version here/ |
Also @pascalbaljet I assume with access to global middleware, things like |
The Laravel PR is already merged, so the easiest way would be to require next week's release as a minimum requirement. It's fine to do that in a minor release, Spatie drops support for Laravel and PHP versions in minor releases as well. Otherwise, you could ditch the macro and check if the method is available. Something like this: /** @var Factory $httpFactory */
$httpFactory = resolve(Factory::class);
$middleware = method_exists($httpFactory, 'getGlobalMiddleware')
? $httpFactory->getGlobalMiddleware()
: [];
$httpPendingRequest = new HttpPendingRequest($httpFactory, $middleware); |
No, I don't think so. In the So when the |
I agree @pascalbaljet - would you mind including this minimum version in this PR and then also remove the macro please? After that, I'll get this PR merged |
@Sammyjo20 I've updated the PR :) |
Hey @Sammyjo20 Are you planning to release a v2.1 with this merged anytime soon? No pressure! I just keep on patching my vendor code over and over again when switching branches and re-installing laravel-http-sender, so would need to fork this project in the meantime. Please let us know if this PR needs further refinement. Thanks. |
Hey @onlime @pascalbaljet absolutely! Apologies I've been really busy with work but I'm currently going through issues/PRs so I'll get this one actioned soon :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny question!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great PR @pascalbaljet and your help @onlime
In Laravel 10.14, Global HTTP middleware was introduced (PR #47525). You may use this to globally set a default User Agent. The Middleware array is passed from the HTTP Factory to a new
PendingRequest
:https://github.com/laravel/framework/blob/fc8f819bef5b4843baadda393c51320ceeb41a70/src/Illuminate/Http/Client/Factory.php#L396-L404
In the
createLaravelPendingRequest()
method ofHttpSender
, a newPendingRequest
is instantiated but without the global middleware. This PR fixes that.One caveat, though: there's no functionality to grab the middleware array from the Factory. So as a workaround, I added a macro. After opening this PR, I'll submit another PR to the Laravel repository to do this more elegantly.