Skip to content

[4.x] Fall back to SERVER_NAME when the request has no Host header - #166

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-request-uri-without-host
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-request-uri-without-host

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

detectRequestUri() builds the request URI as scheme + HTTP_HOST + path. Without a Host header (an HTTP/1.0 request, or a web application booted from the command line) the result is http:///j/index.php, which does not parse, or — when the script name has no leading slash — the first path segment is taken as the host, so uri.base.* and uri.root are wrong (see joomla/joomla-cms#38524).

The host now falls back to SERVER_NAME (with SERVER_PORT appended unless it is the default port of the scheme) and then to the host and port of the existing site_uri option. If none of them is available the behaviour is unchanged.

This is an alternative to #120, which throws from detectRequestUri() instead; that turns a degraded state into a fatal error during construction and breaks most tests.

Testing Instructions

vendor/bin/phpunit --filter testDetectRequestUriWithoutHost covers SERVER_NAME without a port, with a non-default port, with port 80, HTTPS with port 443, and the site_uri fallback. Without the change in src/ the first four error and the last returns http:///j/index.php. The existing testDetectRequestUri cases (with a Host header) are unchanged.

Documentation Changes Required

docs/configuration.md (uri.request) and docs/api-reference.md (detectRequestUri()) describe the fallback.

Alternative to #120

🤖 Generated with Claude Code

detectRequestUri() built the request URI from the scheme and the Host
header only. Without that header (HTTP/1.0 requests, a web application
booted from the command line) the URI became "http:///path", which does
not parse, or the first path segment was taken as the host, so uri.base
and uri.root were wrong.

The host now falls back to SERVER_NAME (with SERVER_PORT unless it is the
default port of the scheme) and then to the host of the site_uri option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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