|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Christoph Wurst <[email protected]> |
|
6
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
|
7
|
|
|
* @author Julius Härtl <[email protected]> |
|
8
|
|
|
* @author Lukas Reschke <[email protected]> |
|
9
|
|
|
* @author Morris Jobke <[email protected]> |
|
10
|
|
|
* @author Robin McCorkell <[email protected]> |
|
11
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
12
|
|
|
* @author Thomas Müller <[email protected]> |
|
13
|
|
|
* @author Thomas Tanghus <[email protected]> |
|
14
|
|
|
* |
|
15
|
|
|
* @license AGPL-3.0 |
|
16
|
|
|
* |
|
17
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
18
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
19
|
|
|
* as published by the Free Software Foundation. |
|
20
|
|
|
* |
|
21
|
|
|
* This program is distributed in the hope that it will be useful, |
|
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24
|
|
|
* GNU Affero General Public License for more details. |
|
25
|
|
|
* |
|
26
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
28
|
|
|
* |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
namespace OC\AppFramework; |
|
32
|
|
|
|
|
33
|
|
|
use OCP\AppFramework\Http as BaseHttp; |
|
34
|
|
|
|
|
35
|
|
|
class Http extends BaseHttp { |
|
36
|
|
|
private $server; |
|
37
|
|
|
private $protocolVersion; |
|
38
|
|
|
protected $headers; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param array $server $_SERVER |
|
42
|
|
|
* @param string $protocolVersion the http version to use defaults to HTTP/1.1 |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct($server, $protocolVersion='HTTP/1.1') { |
|
45
|
|
|
$this->server = $server; |
|
46
|
|
|
$this->protocolVersion = $protocolVersion; |
|
47
|
|
|
|
|
48
|
|
|
$this->headers = [ |
|
49
|
|
|
self::STATUS_CONTINUE => 'Continue', |
|
50
|
|
|
self::STATUS_SWITCHING_PROTOCOLS => 'Switching Protocols', |
|
51
|
|
|
self::STATUS_PROCESSING => 'Processing', |
|
52
|
|
|
self::STATUS_OK => 'OK', |
|
53
|
|
|
self::STATUS_CREATED => 'Created', |
|
54
|
|
|
self::STATUS_ACCEPTED => 'Accepted', |
|
55
|
|
|
self::STATUS_NON_AUTHORATIVE_INFORMATION => 'Non-Authorative Information', |
|
56
|
|
|
self::STATUS_NO_CONTENT => 'No Content', |
|
57
|
|
|
self::STATUS_RESET_CONTENT => 'Reset Content', |
|
58
|
|
|
self::STATUS_PARTIAL_CONTENT => 'Partial Content', |
|
59
|
|
|
self::STATUS_MULTI_STATUS => 'Multi-Status', // RFC 4918 |
|
60
|
|
|
self::STATUS_ALREADY_REPORTED => 'Already Reported', // RFC 5842 |
|
61
|
|
|
self::STATUS_IM_USED => 'IM Used', // RFC 3229 |
|
62
|
|
|
self::STATUS_MULTIPLE_CHOICES => 'Multiple Choices', |
|
63
|
|
|
self::STATUS_MOVED_PERMANENTLY => 'Moved Permanently', |
|
64
|
|
|
self::STATUS_FOUND => 'Found', |
|
65
|
|
|
self::STATUS_SEE_OTHER => 'See Other', |
|
66
|
|
|
self::STATUS_NOT_MODIFIED => 'Not Modified', |
|
67
|
|
|
self::STATUS_USE_PROXY => 'Use Proxy', |
|
68
|
|
|
self::STATUS_RESERVED => 'Reserved', |
|
69
|
|
|
self::STATUS_TEMPORARY_REDIRECT => 'Temporary Redirect', |
|
70
|
|
|
self::STATUS_BAD_REQUEST => 'Bad request', |
|
71
|
|
|
self::STATUS_UNAUTHORIZED => 'Unauthorized', |
|
72
|
|
|
self::STATUS_PAYMENT_REQUIRED => 'Payment Required', |
|
73
|
|
|
self::STATUS_FORBIDDEN => 'Forbidden', |
|
74
|
|
|
self::STATUS_NOT_FOUND => 'Not Found', |
|
75
|
|
|
self::STATUS_METHOD_NOT_ALLOWED => 'Method Not Allowed', |
|
76
|
|
|
self::STATUS_NOT_ACCEPTABLE => 'Not Acceptable', |
|
77
|
|
|
self::STATUS_PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required', |
|
78
|
|
|
self::STATUS_REQUEST_TIMEOUT => 'Request Timeout', |
|
79
|
|
|
self::STATUS_CONFLICT => 'Conflict', |
|
80
|
|
|
self::STATUS_GONE => 'Gone', |
|
81
|
|
|
self::STATUS_LENGTH_REQUIRED => 'Length Required', |
|
82
|
|
|
self::STATUS_PRECONDITION_FAILED => 'Precondition failed', |
|
83
|
|
|
self::STATUS_REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large', |
|
84
|
|
|
self::STATUS_REQUEST_URI_TOO_LONG => 'Request-URI Too Long', |
|
85
|
|
|
self::STATUS_UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type', |
|
86
|
|
|
self::STATUS_REQUEST_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable', |
|
87
|
|
|
self::STATUS_EXPECTATION_FAILED => 'Expectation Failed', |
|
88
|
|
|
self::STATUS_IM_A_TEAPOT => 'I\'m a teapot', // RFC 2324 |
|
89
|
|
|
self::STATUS_UNPROCESSABLE_ENTITY => 'Unprocessable Entity', // RFC 4918 |
|
90
|
|
|
self::STATUS_LOCKED => 'Locked', // RFC 4918 |
|
91
|
|
|
self::STATUS_FAILED_DEPENDENCY => 'Failed Dependency', // RFC 4918 |
|
92
|
|
|
self::STATUS_UPGRADE_REQUIRED => 'Upgrade required', |
|
93
|
|
|
self::STATUS_PRECONDITION_REQUIRED => 'Precondition required', // draft-nottingham-http-new-status |
|
94
|
|
|
self::STATUS_TOO_MANY_REQUESTS => 'Too Many Requests', // draft-nottingham-http-new-status |
|
95
|
|
|
self::STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large', // draft-nottingham-http-new-status |
|
96
|
|
|
self::STATUS_INTERNAL_SERVER_ERROR => 'Internal Server Error', |
|
97
|
|
|
self::STATUS_NOT_IMPLEMENTED => 'Not Implemented', |
|
98
|
|
|
self::STATUS_BAD_GATEWAY => 'Bad Gateway', |
|
99
|
|
|
self::STATUS_SERVICE_UNAVAILABLE => 'Service Unavailable', |
|
100
|
|
|
self::STATUS_GATEWAY_TIMEOUT => 'Gateway Timeout', |
|
101
|
|
|
self::STATUS_HTTP_VERSION_NOT_SUPPORTED => 'HTTP Version not supported', |
|
102
|
|
|
self::STATUS_VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates', |
|
103
|
|
|
self::STATUS_INSUFFICIENT_STORAGE => 'Insufficient Storage', // RFC 4918 |
|
104
|
|
|
self::STATUS_LOOP_DETECTED => 'Loop Detected', // RFC 5842 |
|
105
|
|
|
self::STATUS_BANDWIDTH_LIMIT_EXCEEDED => 'Bandwidth Limit Exceeded', // non-standard |
|
106
|
|
|
self::STATUS_NOT_EXTENDED => 'Not extended', |
|
107
|
|
|
self::STATUS_NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required', // draft-nottingham-http-new-status |
|
108
|
|
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Gets the correct header |
|
114
|
|
|
* @param int Http::CONSTANT $status the constant from the Http class |
|
115
|
|
|
* @param \DateTime $lastModified formatted last modified date |
|
116
|
|
|
* @param string $ETag the etag |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getStatusHeader($status) { |
|
120
|
|
|
// we have one change currently for the http 1.0 header that differs |
|
121
|
|
|
// from 1.1: STATUS_TEMPORARY_REDIRECT should be STATUS_FOUND |
|
122
|
|
|
// if this differs any more, we want to create childclasses for this |
|
123
|
|
|
if ($status === self::STATUS_TEMPORARY_REDIRECT |
|
124
|
|
|
&& $this->protocolVersion === 'HTTP/1.0') { |
|
125
|
|
|
$status = self::STATUS_FOUND; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $this->protocolVersion . ' ' . $status . ' ' . |
|
129
|
|
|
$this->headers[$status]; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|