Repository navigation
fix: flush queued cookies between requests in LaravelHttpServer - #257
Merged
MrPunyapal merged 2 commits intoSep 14, 2026
Merged
Conversation
The in-process server reuses one container, so the CookieJar singleton kept every cookie queued through Cookie::queue() and AddQueuedCookiesToResponse re-sent it on every later response of the same test. FPM discards the jar with the process and Octane flushes it per request; do the same before handling each request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LaravelHttpServerserves every request of a browser test from one long-lived container. Cookies queued throughCookie::queue()land in theCookieJarsingleton, andAddQueuedCookiesToResponseattaches every queued cookie to a response but never removes it from the jar. Nothing else does either:So a cookie queued by the first request is re-sent on every later response of the same test, including responses of routes that never queued anything.
Impact
A browser test cannot verify which response hands a cookie to the browser, and a cookie a page deliberately queues once (for example a first-party attribution cookie written on the first page after consent) shows up on every Livewire/XHR response afterwards. It also masks application bugs: code that forgets to queue a cookie on a later page still "works" in the test because the stale queue is replayed. We hit this while testing a consent-dependent cookie hand-over in a Laravel app: the assertion "exactly one response carried the cookie" saw five.
Fix
Flush the jar before handling each request, next to the existing
forgetScopedInstances()(same per-request lifecycle FPM and Octane provide):Test
it does not re-send a cookie queued in an earlier requestrecords theSet-Cookieheaders of two requests throughRequestHandled: the first route queues a cookie, the second does not. On the unfixed source the cookie appears on both responses (['queue-cookie', 'no-cookie']); with the fix only on the first.Run:
vendor/bin/pest tests/Unit/Drivers/Laravel/LaravelHttpServerTest.php(6 passed).