]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/HTTP/Response.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / HTTP / Response.php
1 <?php
2
3 /**
4  * Sabre_HTTP_Response
5  *
6  * @package Sabre
7  * @subpackage HTTP 
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
11  */
12 class Sabre_HTTP_Response {
13
14     /**
15      * Returns a full HTTP status message for an HTTP status code
16      *
17      * @param int $code
18      * @return string
19      */
20     public function getStatusMessage($code) {
21
22         $msg = array(
23             100 => 'Continue',
24             101 => 'Switching Protocols',
25             102 => 'Processing',
26             200 => 'OK',
27             201 => 'Created',
28             202 => 'Accepted',
29             203 => 'Non-Authorative Information',
30             204 => 'No Content',
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',
38             302 => 'Found',
39             303 => 'See Other',
40             304 => 'Not Modified',
41             305 => 'Use Proxy',
42             306 => 'Reserved',
43             307 => 'Temporary Redirect',
44             400 => 'Bad request',
45             401 => 'Unauthorized',
46             402 => 'Payment Required',
47             403 => 'Forbidden',
48             404 => 'Not Found',
49             405 => 'Method Not Allowed',
50             406 => 'Not Acceptable',
51             407 => 'Proxy Authentication Required',
52             408 => 'Request Timeout',
53             409 => 'Conflict',
54             410 => 'Gone',
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',
72             502 => 'Bad Gateway',
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
82        );
83
84        return 'HTTP/1.1 ' . $code . ' ' . $msg[$code];
85
86     }
87
88     /**
89      * Sends an HTTP status header to the client
90      *
91      * @param int $code HTTP status code
92      * @return bool
93      */
94     public function sendStatus($code) {
95
96         if (!headers_sent())
97             return header($this->getStatusMessage($code));
98         else return false;
99
100     }
101
102     /**
103      * Sets an HTTP header for the response
104      *
105      * @param string $name
106      * @param string $value
107      * @param bool $replace
108      * @return bool
109      */
110     public function setHeader($name, $value, $replace = true) {
111
112         $value = str_replace(array("\r","\n"),array('\r','\n'),$value);
113         if (!headers_sent())
114             return header($name . ': ' . $value, $replace);
115         else return false;
116
117     }
118
119     /**
120      * Sets a bunch of HTTP Headers
121      *
122      * headersnames are specified as keys, value in the array value
123      *
124      * @param array $headers
125      * @return void
126      */
127     public function setHeaders(array $headers) {
128
129         foreach($headers as $key=>$value)
130             $this->setHeader($key, $value);
131
132     }
133
134     /**
135      * Sends the entire response body
136      *
137      * This method can accept either an open filestream, or a string.
138      *
139      * @param mixed $body
140      * @return void
141      */
142     public function sendBody($body) {
143
144         if (is_resource($body)) {
145
146             fpassthru($body);
147
148         } else {
149
150             // We assume a string
151             echo $body;
152
153         }
154
155     }
156
157 }