diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 950bffd2a5b5..25d134953db6 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -165,6 +165,7 @@ static public function create($uri, $method = 'GET', $parameters = array(), $coo 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'SCRIPT_FILENAME' => '', + 'SERVER_PROTOCOL' => 'HTTP/1.1', ); $components = parse_url($uri); @@ -280,6 +281,32 @@ public function __clone() $this->headers = clone $this->headers; } + /** + * Returns the request as a string. + * + * @return string The request + */ + public function __toString() + { + // status + $content = sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n"; + + $beautifier = function ($name) { + return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", ucfirst($name)); + }; + + // headers + foreach ($this->headers->all() as $name => $values) { + foreach ($values as $value) { + $content .= sprintf("%s: %s\r\n", $beautifier($name), $value); + } + } + + $content .= "\r\n".$this->getContent(); + + return $content; + } + /** * Overrides the PHP global variables according to this request instance. * diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 964c313a95e9..b5b7ce7a9791 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -96,17 +96,19 @@ public function __construct($content = '', $status = 200, $headers = array()) */ public function __toString() { - $content = ''; - $this->fixContentType(); // status - $content .= sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n"; + $content = sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n"; + + $beautifier = function ($name) { + return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", ucfirst($name)); + }; // headers foreach ($this->headers->all() as $name => $values) { foreach ($values as $value) { - $content .= "$name: $value\r\n"; + $content .= sprintf("%s: %s\r\n", $beautifier($name), $value); } }