Clear stale HTTP_* headers from $_SERVER between persistent PHP dispatches#119
Merged
Conversation
Inertia visits left HTTP_X_INERTIA in $_SERVER, so a subsequent window.location.href navigation returned JSON instead of HTML. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
Fixes raw Inertia JSON being rendered after a top-level navigation following an Inertia visit (reported on iOS, latent on Android).
In the persistent PHP runtime,
$_SERVERis a regular superglobal that survives acrosszend_eval_string()dispatches. The dispatch eval layered new env vars on top withforeach (getenv() as $__k => $__v) { $_SERVER[$__k] = $__v; }but never removed keys from prior requests. Once an Inertia XHR setHTTP_X_INERTIA = 'true', that key remained in$_SERVERfor every subsequent request — even after the C-level env var was unset — so a plainwindow.location.href = '/home'navigation hit Inertia's middleware and got JSON back.This patch strips
HTTP_*,CONTENT_TYPE, andCONTENT_LENGTHkeys from$_SERVERat the top of every dispatch in both the iOS (PHP.c) and Android (php_bridge.c) eval blocks, addressing the root cause for any stale request header rather than a single Inertia-specific symptom.The existing Kotlin band-aid in
PHPBridge.kt(which zeroes the five Inertia-specific env vars before each dispatch) becomes redundant but is left in place as defense-in-depth — happy to remove on request.Test plan
window.location.href = '/home'on iOS — confirm full HTML loads, not raw JSONContent-Typecontinue to parse$_POSTcorrectly after the clearing step🤖 Generated with Claude Code