Skip to content

[12.x] Add allowedUrls through preventStrayRequests #56645

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

Merged
merged 6 commits into from
Aug 13, 2025

Conversation

rabrowne85
Copy link
Contributor

The purpose behind Http::preventStrayRequests() is great - it stops any stray requests from hitting endpoints.
However, this also means that if you’re trying to use SSR to check the output from something like Inertia, those requests will be blocked and a StrayRequestException will be thrown.

This PR expands the existing Http::allowStrayRequests() method to accept an array of “allowed” URLs.
For example:

Http::allowStrayRequests([
    'http://127.0.0.1:13714/*',
]);

To keep things fully backward-compatible, calling allowStrayRequests() without arguments still turns preventStrayRequests off entirely, as it did before.

Both the Http\Client\Factory and Http\Client\PendingResponse classes have been adjusted to accept and pass the allowed list of URLs.

I’ve added a simple test to ensure the allow-list logic works.
I avoided adding a test that actually hits a real endpoint, since depending on when/how the tests are run, the result could vary - even for 127.0.0.1.

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@rabrowne85 rabrowne85 marked this pull request as ready for review August 13, 2025 15:49
@taylorotwell taylorotwell merged commit a97fa06 into laravel:12.x Aug 13, 2025
60 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