Repository navigation
[6.x] Fix CP downloads for Inertia requests on inertia-laravel 3.5.2 - #15697
Merged
Merged
Conversation
inertia-laravel 3.5.2 no longer passes streamed and binary file responses to onEmptyResponse, so downloads were no longer converted into location visits. Convert them before the parent middleware handles the response, which works across all supported versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
inertia-laravel 3.5.2 (inertiajs/inertia-laravel#919) changed its empty response check from
empty($response->getContent())to$response->getContent() === ''. Streamed and binary file responses returnfalsefromgetContent(), so they no longer reachonEmptyResponse(). Our override there, which converts CP downloads intoInertia::location()visits so the browser can handle them, stopped running. This is what's failingHandleInertiaRequestsTestin CI.This moves the conversion into
handle()by wrapping$next, so downloads are converted before the parent middleware sees the response. It can't simply check afterparent::handle(), because older versions would already have turned the download into a redirect back by then.Behaviour is unchanged on inertia-laravel 2.x and 3.x (tested on 2.0.28, 3.5.1 and 3.5.2). The only difference is that the 409 location response now also carries the
Vary: X-Inertiaheader.