{"action":"created","issue":{"url":"https://api.github.com/repos/php-fig/fig-standards/issues/296","labels_url":"https://api.github.com/repos/php-fig/fig-standards/issues/296/labels{/name}","comments_url":"https://api.github.com/repos/php-fig/fig-standards/issues/296/comments","events_url":"https://api.github.com/repos/php-fig/fig-standards/issues/296/events","html_url":"https://github.com/php-fig/fig-standards/issues/296","id":36722153,"number":296,"title":"[HTTP Message] What should Request::getUrl() return when no Host header is present?","user":{"login":"BenMorel","id":1952838,"avatar_url":"https://avatars.githubusercontent.com/u/1952838?v=3","gravatar_id":"","url":"https://api.github.com/users/BenMorel","html_url":"https://github.com/BenMorel","followers_url":"https://api.github.com/users/BenMorel/followers","following_url":"https://api.github.com/users/BenMorel/following{/other_user}","gists_url":"https://api.github.com/users/BenMorel/gists{/gist_id}","starred_url":"https://api.github.com/users/BenMorel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BenMorel/subscriptions","organizations_url":"https://api.github.com/users/BenMorel/orgs","repos_url":"https://api.github.com/users/BenMorel/repos","events_url":"https://api.github.com/users/BenMorel/events{/privacy}","received_events_url":"https://api.github.com/users/BenMorel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":33,"created_at":"2014-06-28T09:56:16Z","updated_at":"2015-01-06T16:39:42Z","closed_at":null,"body":"This is the current documentation for `Request::getUrl()`:\r\n\r\n    /**\r\n     * Gets the absolute request URL.\r\n     *\r\n     * @return string Returns the URL as a string.\r\n     */\r\n    public function getUrl();\r\n\r\nThe problem is, to construct a full URL we need the contents of the `Host` header, which although mandatory in HTTP 1.1, is optional in HTTP 1.0.\r\n\r\nSo the implementer is left in the dark about what to do when no `Host` is present, such as when parsing the following valid request:\r\n\r\n    GET /resource HTTP/1.0\r\n\r\nI can see a few options:\r\n\r\n- Throw an exception\r\n- Return an invalid URL with no host: `http:///resource`\r\n- Return a valid URL with a default host: `http://localhost/resource`\r\n\r\nI have no personal preference, but I think it's important to document what to do in that case!"},"comment":{"url":"https://api.github.com/repos/php-fig/fig-standards/issues/comments/68890867","html_url":"https://github.com/php-fig/fig-standards/issues/296#issuecomment-68890867","issue_url":"https://api.github.com/repos/php-fig/fig-standards/issues/296","id":68890867,"user":{"login":"weierophinney","id":25943,"avatar_url":"https://avatars.githubusercontent.com/u/25943?v=3","gravatar_id":"","url":"https://api.github.com/users/weierophinney","html_url":"https://github.com/weierophinney","followers_url":"https://api.github.com/users/weierophinney/followers","following_url":"https://api.github.com/users/weierophinney/following{/other_user}","gists_url":"https://api.github.com/users/weierophinney/gists{/gist_id}","starred_url":"https://api.github.com/users/weierophinney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weierophinney/subscriptions","organizations_url":"https://api.github.com/users/weierophinney/orgs","repos_url":"https://api.github.com/users/weierophinney/repos","events_url":"https://api.github.com/users/weierophinney/events{/privacy}","received_events_url":"https://api.github.com/users/weierophinney/received_events","type":"User","site_admin":false},"created_at":"2015-01-06T16:39:42Z","updated_at":"2015-01-06T16:39:42Z","body":"@BenMorel - `$_SERVER` represents the parameters provided by the Server API (SAPI), which reflect the Common Gateway Interface (CGI) standard. They _are_ part of the request, and if you look at request implementations in other languages (such as Rack and WSGI), you'll see the same information present. They values **MUST** be present -- as @simensen notes, all of the data used to construct things like the URL comes from `$_SERVER`, which allows us to later re-construct that information if desired (e.g., to return a request to its original state)."}}