|
@@ -71,67 +71,78 @@ class Response
|
|
|
/**
|
|
/**
|
|
|
* Phrases.
|
|
* Phrases.
|
|
|
*
|
|
*
|
|
|
- * @var array
|
|
|
|
|
|
|
+ * @var array<int,string>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
|
|
|
*/
|
|
*/
|
|
|
- protected static $_phrases = [
|
|
|
|
|
|
|
+ const PHRASES = [
|
|
|
100 => 'Continue',
|
|
100 => 'Continue',
|
|
|
101 => 'Switching Protocols',
|
|
101 => 'Switching Protocols',
|
|
|
- 102 => 'Processing',
|
|
|
|
|
|
|
+ 102 => 'Processing', // WebDAV; RFC 2518
|
|
|
|
|
+ 103 => 'Early Hints', // RFC 8297
|
|
|
|
|
+
|
|
|
200 => 'OK',
|
|
200 => 'OK',
|
|
|
201 => 'Created',
|
|
201 => 'Created',
|
|
|
202 => 'Accepted',
|
|
202 => 'Accepted',
|
|
|
- 203 => 'Non-Authoritative Information',
|
|
|
|
|
|
|
+ 203 => 'Non-Authoritative Information', // since HTTP/1.1
|
|
|
204 => 'No Content',
|
|
204 => 'No Content',
|
|
|
205 => 'Reset Content',
|
|
205 => 'Reset Content',
|
|
|
- 206 => 'Partial Content',
|
|
|
|
|
- 207 => 'Multi-status',
|
|
|
|
|
- 208 => 'Already Reported',
|
|
|
|
|
|
|
+ 206 => 'Partial Content', // RFC 7233
|
|
|
|
|
+ 207 => 'Multi-Status', // WebDAV; RFC 4918
|
|
|
|
|
+ 208 => 'Already Reported', // WebDAV; RFC 5842
|
|
|
|
|
+ 226 => 'IM Used', // RFC 3229
|
|
|
|
|
+
|
|
|
300 => 'Multiple Choices',
|
|
300 => 'Multiple Choices',
|
|
|
301 => 'Moved Permanently',
|
|
301 => 'Moved Permanently',
|
|
|
- 302 => 'Found',
|
|
|
|
|
- 303 => 'See Other',
|
|
|
|
|
- 304 => 'Not Modified',
|
|
|
|
|
- 305 => 'Use Proxy',
|
|
|
|
|
|
|
+ 302 => 'Found', // Previously "Moved temporarily"
|
|
|
|
|
+ 303 => 'See Other', // since HTTP/1.1
|
|
|
|
|
+ 304 => 'Not Modified', // RFC 7232
|
|
|
|
|
+ 305 => 'Use Proxy', // since HTTP/1.1
|
|
|
306 => 'Switch Proxy',
|
|
306 => 'Switch Proxy',
|
|
|
- 307 => 'Temporary Redirect',
|
|
|
|
|
|
|
+ 307 => 'Temporary Redirect', // since HTTP/1.1
|
|
|
|
|
+ 308 => 'Permanent Redirect', // RFC 7538
|
|
|
|
|
+
|
|
|
400 => 'Bad Request',
|
|
400 => 'Bad Request',
|
|
|
- 401 => 'Unauthorized',
|
|
|
|
|
|
|
+ 401 => 'Unauthorized', // RFC 7235
|
|
|
402 => 'Payment Required',
|
|
402 => 'Payment Required',
|
|
|
403 => 'Forbidden',
|
|
403 => 'Forbidden',
|
|
|
404 => 'Not Found',
|
|
404 => 'Not Found',
|
|
|
405 => 'Method Not Allowed',
|
|
405 => 'Method Not Allowed',
|
|
|
406 => 'Not Acceptable',
|
|
406 => 'Not Acceptable',
|
|
|
- 407 => 'Proxy Authentication Required',
|
|
|
|
|
- 408 => 'Request Time-out',
|
|
|
|
|
|
|
+ 407 => 'Proxy Authentication Required', // RFC 7235
|
|
|
|
|
+ 408 => 'Request Timeout',
|
|
|
409 => 'Conflict',
|
|
409 => 'Conflict',
|
|
|
410 => 'Gone',
|
|
410 => 'Gone',
|
|
|
411 => 'Length Required',
|
|
411 => 'Length Required',
|
|
|
- 412 => 'Precondition Failed',
|
|
|
|
|
- 413 => 'Request Entity Too Large',
|
|
|
|
|
- 414 => 'Request-URI Too Large',
|
|
|
|
|
- 415 => 'Unsupported Media Type',
|
|
|
|
|
- 416 => 'Requested range not satisfiable',
|
|
|
|
|
|
|
+ 412 => 'Precondition Failed', // RFC 7232
|
|
|
|
|
+ 413 => 'Payload Too Large', // RFC 7231
|
|
|
|
|
+ 414 => 'URI Too Long', // RFC 7231
|
|
|
|
|
+ 415 => 'Unsupported Media Type', // RFC 7231
|
|
|
|
|
+ 416 => 'Range Not Satisfiable', // RFC 7233
|
|
|
417 => 'Expectation Failed',
|
|
417 => 'Expectation Failed',
|
|
|
- 418 => 'I\'m a teapot',
|
|
|
|
|
- 422 => 'Unprocessable Entity',
|
|
|
|
|
- 423 => 'Locked',
|
|
|
|
|
- 424 => 'Failed Dependency',
|
|
|
|
|
- 425 => 'Unordered Collection',
|
|
|
|
|
|
|
+ 418 => 'I\'m a teapot', // RFC 2324, RFC 7168
|
|
|
|
|
+ 421 => 'Misdirected Request', // RFC 7540
|
|
|
|
|
+ 422 => 'Unprocessable Entity', // WebDAV; RFC 4918
|
|
|
|
|
+ 423 => 'Locked', // WebDAV; RFC 4918
|
|
|
|
|
+ 424 => 'Failed Dependency', // WebDAV; RFC 4918
|
|
|
|
|
+ 425 => 'Too Early', // RFC 8470
|
|
|
426 => 'Upgrade Required',
|
|
426 => 'Upgrade Required',
|
|
|
- 428 => 'Precondition Required',
|
|
|
|
|
- 429 => 'Too Many Requests',
|
|
|
|
|
- 431 => 'Request Header Fields Too Large',
|
|
|
|
|
- 451 => 'Unavailable For Legal Reasons',
|
|
|
|
|
|
|
+ 428 => 'Precondition Required', // RFC 6585
|
|
|
|
|
+ 429 => 'Too Many Requests', // RFC 6585
|
|
|
|
|
+ 431 => 'Request Header Fields Too Large', // RFC 6585
|
|
|
|
|
+ 451 => 'Unavailable For Legal Reasons', // RFC 7725
|
|
|
|
|
+
|
|
|
500 => 'Internal Server Error',
|
|
500 => 'Internal Server Error',
|
|
|
501 => 'Not Implemented',
|
|
501 => 'Not Implemented',
|
|
|
502 => 'Bad Gateway',
|
|
502 => 'Bad Gateway',
|
|
|
503 => 'Service Unavailable',
|
|
503 => 'Service Unavailable',
|
|
|
- 504 => 'Gateway Time-out',
|
|
|
|
|
- 505 => 'HTTP Version not supported',
|
|
|
|
|
- 506 => 'Variant Also Negotiates',
|
|
|
|
|
- 507 => 'Insufficient Storage',
|
|
|
|
|
- 508 => 'Loop Detected',
|
|
|
|
|
- 511 => 'Network Authentication Required',
|
|
|
|
|
|
|
+ 504 => 'Gateway Timeout',
|
|
|
|
|
+ 505 => 'HTTP Version Not Supported',
|
|
|
|
|
+ 506 => 'Variant Also Negotiates', // RFC 2295
|
|
|
|
|
+ 507 => 'Insufficient Storage', // WebDAV; RFC 4918
|
|
|
|
|
+ 508 => 'Loop Detected', // WebDAV; RFC 5842
|
|
|
|
|
+ 510 => 'Not Extended', // RFC 2774
|
|
|
|
|
+ 511 => 'Network Authentication Required', // RFC 6585
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -354,7 +365,7 @@ class Response
|
|
|
protected function createHeadForFile($file_info)
|
|
protected function createHeadForFile($file_info)
|
|
|
{
|
|
{
|
|
|
$file = $file_info['file'];
|
|
$file = $file_info['file'];
|
|
|
- $reason = $this->_reason ?: static::$_phrases[$this->_status];
|
|
|
|
|
|
|
+ $reason = $this->_reason ?: self::PHRASES[$this->_status];
|
|
|
$head = "HTTP/{$this->_version} {$this->_status} $reason\r\n";
|
|
$head = "HTTP/{$this->_version} {$this->_status} $reason\r\n";
|
|
|
$headers = $this->_header;
|
|
$headers = $this->_header;
|
|
|
if (!isset($headers['Server'])) {
|
|
if (!isset($headers['Server'])) {
|
|
@@ -409,7 +420,7 @@ class Response
|
|
|
return $this->createHeadForFile($this->file);
|
|
return $this->createHeadForFile($this->file);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $reason = $this->_reason ?: static::$_phrases[$this->_status] ?? '';
|
|
|
|
|
|
|
+ $reason = $this->_reason ?: self::PHRASES[$this->_status] ?? '';
|
|
|
$body_len = \strlen($this->_body);
|
|
$body_len = \strlen($this->_body);
|
|
|
if (empty($this->_header)) {
|
|
if (empty($this->_header)) {
|
|
|
return "HTTP/{$this->_version} {$this->_status} $reason\r\nServer: workerman\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: $body_len\r\nConnection: keep-alive\r\n\r\n{$this->_body}";
|
|
return "HTTP/{$this->_version} {$this->_status} $reason\r\nServer: workerman\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: $body_len\r\nConnection: keep-alive\r\n\r\n{$this->_body}";
|