Skip to content

Commit

Permalink
Add setter/getter for Response HTTP version and ensure the correct HT…
Browse files Browse the repository at this point in the history
…TP version header is set
  • Loading branch information
Josh Lockhart committed Aug 27, 2011
1 parent 0cfcef4 commit 134cdf3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Slim/Http/Response.php
Expand Up @@ -53,6 +53,11 @@ class Slim_Http_Response {
*/
protected $request;

/**
* @var string
*/
protected $httpVersion = '1.1';

/**
* @var int HTTP status code
*/
Expand Down Expand Up @@ -138,6 +143,24 @@ public function __construct( Slim_Http_Request $req ) {
$this->header('Content-Type', 'text/html');
}

/**
* Set and/or get the HTTP response version
* @param string $version
* @return void
* @throws InvalidArgumentException If argument is not a valid HTTP version
*/
public function httpVersion( $version = null ) {
if ( $version ) {
$version = (string)$version;
if ( $version === '1.0' || $version === '1.1' ) {
$this->httpVersion = $version;
} else {
throw new InvalidArgumentException('Invalid HTTP version in Response object');
}
}
return $this->httpVersion;
}

/**
* Set and/or get the HTTP response status code
* @param int $status
Expand Down Expand Up @@ -259,7 +282,7 @@ protected function sendHeaders() {
header('Status: ' . self::getMessageForCode($this->status()));
} else {
//Else send HTTP message
header('HTTP/1.1 ' . self::getMessageForCode($this->status()));
header(sprintf('HTTP/%s %s', $this->httpVersion, self::getMessageForCode($this->status())));
}

//Send headers
Expand Down

0 comments on commit 134cdf3

Please sign in to comment.