8 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
9 * @author Evert Pot (http://www.rooftopsolutions.nl/)
10 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
12 class Sabre_HTTP_Response {
15 * Returns a full HTTP status message for an HTTP status code
20 public function getStatusMessage($code) {
24 101 => 'Switching Protocols',
29 203 => 'Non-Authorative Information',
31 205 => 'Reset Content',
32 206 => 'Partial Content',
33 207 => 'Multi-Status', // RFC 4918
34 208 => 'Already Reported', // RFC 5842
35 226 => 'IM Used', // RFC 3229
36 300 => 'Multiple Choices',
37 301 => 'Moved Permanently',
40 304 => 'Not Modified',
43 307 => 'Temporary Redirect',
45 401 => 'Unauthorized',
46 402 => 'Payment Required',
49 405 => 'Method Not Allowed',
50 406 => 'Not Acceptable',
51 407 => 'Proxy Authentication Required',
52 408 => 'Request Timeout',
55 411 => 'Length Required',
56 412 => 'Precondition failed',
57 413 => 'Request Entity Too Large',
58 414 => 'Request-URI Too Long',
59 415 => 'Unsupported Media Type',
60 416 => 'Requested Range Not Satisfiable',
61 417 => 'Expectation Failed',
62 418 => 'I\'m a teapot', // RFC 2324
63 422 => 'Unprocessable Entity', // RFC 4918
64 423 => 'Locked', // RFC 4918
65 424 => 'Failed Dependency', // RFC 4918
66 426 => 'Upgrade required',
67 428 => 'Precondition required', // draft-nottingham-http-new-status
68 429 => 'Too Many Requests', // draft-nottingham-http-new-status
69 431 => 'Request Header Fields Too Large', // draft-nottingham-http-new-status
70 500 => 'Internal Server Error',
71 501 => 'Not Implemented',
73 503 => 'Service Unavailable',
74 504 => 'Gateway Timeout',
75 505 => 'HTTP Version not supported',
76 506 => 'Variant Also Negotiates',
77 507 => 'Insufficient Storage', // RFC 4918
78 508 => 'Loop Detected', // RFC 5842
79 509 => 'Bandwidth Limit Exceeded', // non-standard
80 510 => 'Not extended',
81 511 => 'Network Authentication Required', // draft-nottingham-http-new-status
84 return 'HTTP/1.1 ' . $code . ' ' . $msg[$code];
89 * Sends an HTTP status header to the client
91 * @param int $code HTTP status code
94 public function sendStatus($code) {
97 return header($this->getStatusMessage($code));
103 * Sets an HTTP header for the response
105 * @param string $name
106 * @param string $value
107 * @param bool $replace
110 public function setHeader($name, $value, $replace = true) {
112 $value = str_replace(array("\r","\n"),array('\r','\n'),$value);
114 return header($name . ': ' . $value, $replace);
120 * Sets a bunch of HTTP Headers
122 * headersnames are specified as keys, value in the array value
124 * @param array $headers
127 public function setHeaders(array $headers) {
129 foreach($headers as $key=>$value)
130 $this->setHeader($key, $value);
135 * Sends the entire response body
137 * This method can accept either an open filestream, or a string.
142 public function sendBody($body) {
144 if (is_resource($body)) {
150 // We assume a string