Skip to content

Fix canonical URL handling for subdomain routing#224

Open
hafezdivandari wants to merge 10 commits into
pestphp:4.xfrom
hafezdivandari:4.x-fix-canonical-url
Open

Fix canonical URL handling for subdomain routing#224
hafezdivandari wants to merge 10 commits into
pestphp:4.xfrom
hafezdivandari:4.x-fix-canonical-url

Conversation

@hafezdivandari

Copy link
Copy Markdown

This PR introduces a single canonical-URL concept in LaravelHttpServer (canonicalHost() / canonicalUrl(), re-synced via syncCanonicalUrl()) and fixes two bugs that stemmed from inconsistent host/URL handling.

  1. Subdomain routing bug
    Previously, the configured host (withHost(...)) was only applied ad-hoc to the Host header inside the request handler, while Laravel's app.url, route(), and asset() still pointed at the bound socket IP (127.0.0.1). This left URL generation and subdomain routing inconsistent with the host the browser was actually navigating to.
    Now the canonical host is resolved in one place and synced into app.url and the URL generator's origin/asset origin/scheme. The framework consistently sees the canonical host (e.g. for subdomain routing) even when the request arrived over a different network host like 127.0.0.1. Syncing happens on boot, when the host changes via withHost() (wired through Configuration::setHost()), and per-request as a safety net.

  2. Amp 128 KiB body limit bug
    Amp's SocketHttpServer::createForDirectAccess() defaults to a 128 KiB body size limit, which caused deadlocks/hangs when reading large JSON payloads in POST/PUT/PATCH requests. The server is now created with an explicit DefaultHttpDriverFactory raising the body size limit to 64 MiB, allowing large request bodies to be read without stalling.

the new withHost() contract requires a hostname that resolves to the loopback (any *.localhost works on macOS/modern Linux via nss-myhostname); arbitrary
  made-up TLDs like test.domain no longer work because the browser actually navigates to that host instead of the plugin spoofing the Host header. Worth calling out in the PR description as a behavior
  change.
@hafezdivandari hafezdivandari marked this pull request as ready for review June 4, 2026 13:10
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.

1 participant