From 43330d76e2ca778339e4ecd0707bc5dd106fc336 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Sun, 1 Mar 2015 15:06:47 -0600 Subject: [PATCH 1/2] Detail Host header sources Per the [related PR for fig-standards](php-fig/fig-standards#446), this PR updates the `RequestInterface` to override the `getHeader()` method and indicate that the Host header should be pulled from the composed URI if no value has been previously set. --- src/RequestInterface.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/RequestInterface.php b/src/RequestInterface.php index ab12daf..0166583 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -20,6 +20,22 @@ */ interface RequestInterface extends MessageInterface { + /** + * Extends MessageInterface::getHeader() to provide request-specific + * behavior. + * + * This method acts exactly like MessageInterface::getHeader(), with + * one behavioral change: if the Host header is requested, but has + * not been previously set, the method SHOULD attempt to pull the host + * segment of the composed URI, if present. + * + * @see MessageInterface::getHeader() + * @see UriInterface::getHost() + * @param string $name Case-insensitive header field name. + * @return string + */ + public function getHeader($name); + /** * Retrieves the message's request target. * From 7d932c5e9279e0c15a51b4b90fcf46799d0b5979 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 3 Mar 2015 16:21:43 -0600 Subject: [PATCH 2/2] Host header access is non-optional, via all accessors - Made Host header retrieval non-optional - Added overrides for getHeaders() and getHeaderLines() to ensure they always return the Host header as well. --- src/RequestInterface.php | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/RequestInterface.php b/src/RequestInterface.php index 0166583..692c5f4 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -20,13 +20,31 @@ */ interface RequestInterface extends MessageInterface { + /** + * Extends MessageInterface::getHeaders() to provide request-specific + * behavior. + * + * Retrieves all message headers. + * + * This method acts exactly like MessageInterface::getHeaders(), with one + * behavioral change: if the Host header has not been previously set, the + * method MUST attempt to pull the host segment of the composed URI, if + * present. + * + * @see MessageInterface::getHeaders() + * @see UriInterface::getHost() + * @return array Returns an associative array of the message's headers. Each + * key MUST be a header name, and each value MUST be an array of strings. + */ + public function getHeaders(); + /** * Extends MessageInterface::getHeader() to provide request-specific * behavior. * * This method acts exactly like MessageInterface::getHeader(), with * one behavioral change: if the Host header is requested, but has - * not been previously set, the method SHOULD attempt to pull the host + * not been previously set, the method MUST attempt to pull the host * segment of the composed URI, if present. * * @see MessageInterface::getHeader() @@ -36,6 +54,24 @@ interface RequestInterface extends MessageInterface */ public function getHeader($name); + /** + * Extends MessageInterface::getHeaderLines() to provide request-specific + * behavior. + * + * Retrieves a header by the given case-insensitive name as an array of strings. + * + * This method acts exactly like MessageInterface::getHeaderLines(), with + * one behavioral change: if the Host header is requested, but has + * not been previously set, the method MUST attempt to pull the host + * segment of the composed URI, if present. + * + * @see MessageInterface::getHeaderLines() + * @see UriInterface::getHost() + * @param string $name Case-insensitive header field name. + * @return string[] + */ + public function getHeaderLines($name); + /** * Retrieves the message's request target. *