Skip to content
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

[11.x] Add middleware before sending request and dispatching events #52323

Merged

Conversation

eduance
Copy link
Contributor

@eduance eduance commented Jul 30, 2024

Backstory
See my comment.

Problem

The problem is that we currently do not initialise the middleware before sending the request which causes an issue further described in #51980.

Http::globalRequestMiddleware(fn ($request) => $request->withHeader(
    'User-Agent', 'Example Application/1.0'
));

Solution
We should always first add the middleware to the stack and then build any follow-up handler.

This now causes our middleware to be initialised at the right time and the user-agent is now correctly set when listening to the RequestSending event.

Please let me know if there is a way I could improve this test! :)

@eduance eduance changed the title Fix/add middleware before sending request [11.x] Add middleware before sending request Jul 30, 2024
@eduance eduance changed the title [11.x] Add middleware before sending request [11.x] Add middleware before sending request and dispatching events Jul 30, 2024
@taylorotwell taylorotwell merged commit eb842a9 into laravel:11.x Aug 1, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants