Skip to content

Commit

Permalink
style edits, and add example page to test rfc2324 2.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Young committed Jul 11, 2011
1 parent 1aafcf3 commit 4b8ea47
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cgistream.php
Expand Up @@ -112,9 +112,9 @@ function stream_read($count)

if (isset($headers['Status']))
{
$separator = strpos($headers['Status'], ' ');
$status = (int) substr($headers['Status'], 0, $separator);
$status_msg = trim(substr($headers['Status'], $separator));
$status_arr = explode(' ', $headers['Status'], 2);
$status = (int) $status_arr[0];
$status_msg = trim($status_arr[1]);
unset($headers['Status']);
}
else
Expand Down
5 changes: 5 additions & 0 deletions examples/example_www/brew_coffee.php
@@ -0,0 +1,5 @@
<?php

header("HTTP/1.1 418 I'm a teapot");

echo "<a href='http://tools.ietf.org/html/rfc2324#page-5'>short and stout</a>";
9 changes: 5 additions & 4 deletions httpresponse.php
Expand Up @@ -9,7 +9,7 @@
class HTTPResponse
{
public $status; // HTTP status code
public $status_msg; // HTTP status message
public $status_msg; // HTTP status message
public $headers; // associative array of HTTP headers

public $content = ''; // response body, as string (optional)
Expand Down Expand Up @@ -47,12 +47,13 @@ function stream_eof()
return !$this->stream || feof($this->stream);
}

static function render_status($status, $status_msg)
static function render_status($status, $status_msg = null)
{
// Per RFC2616 6.1.1 we pass on a status message from the provider if
// provided, otherwise we use the standard message for that code.
if (empty($status_msg)) {
$status_msg = static::$status_messages[$status];
if (empty($status_msg))
{
$status_msg = static::$status_messages[$status];
}
return "HTTP/1.1 $status $status_msg\r\n";
}
Expand Down

0 comments on commit 4b8ea47

Please sign in to comment.