-
Notifications
You must be signed in to change notification settings - Fork 0
/
Http.hh
261 lines (247 loc) · 7.2 KB
/
Http.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?hh // strict
/**
* @copyright 2010-2015, The Titon Project
* @license http://opensource.org/licenses/bsd-license.php
* @link http://titon.io
*/
namespace Titon\Http;
use Titon\Http\Exception\InvalidStatusException;
/**
* HTTP related constants and static variables.
*
* @package Titon\Http
*/
class Http {
const string DATE_FORMAT = 'D, d M Y H:i:s T';
const string HTTP_10 = 'HTTP/1.0';
const string HTTP_11 = 'HTTP/1.1';
const int CONTINUE_REQUEST = 100;
const int SWITCHING_PROTOCOLS = 101;
const int PROCESSING = 102;
const int OK = 200;
const int CREATED = 201;
const int ACCEPTED = 202;
const int NON_AUTHORITATIVE_INFORMATION = 203;
const int NO_CONTENT = 204;
const int RESET_CONTENT = 205;
const int PARTIAL_CONTENT = 206;
const int MULTI_STATUS = 207;
const int MULTIPLE_CHOICES = 300;
const int MOVED_PERMANENTLY = 301;
const int FOUND = 302;
const int SEE_OTHER = 303;
const int NOT_MODIFIED = 304;
const int USE_PROXY = 305;
const int TEMPORARY_REDIRECT = 307;
const int BAD_REQUEST = 400;
const int UNAUTHORIZED = 401;
const int PAYMENT_REQUIRED = 402;
const int FORBIDDEN = 403;
const int NOT_FOUND = 404;
const int METHOD_NOT_ALLOWED = 405;
const int NOT_ACCEPTABLE = 406;
const int PROXY_AUTHENTICATION_REQUIRED = 407;
const int REQUEST_TIMEOUT = 408;
const int CONFLICT = 409;
const int GONE = 410;
const int LENGTH_REQUIRED = 411;
const int PRECONDITION_FAILED = 412;
const int REQUEST_ENTITY_TOO_LARGE = 413;
const int REQUEST_URI_TOO_LONG = 414;
const int UNSUPPORTED_MEDIA_TYPE = 415;
const int REQUESTED_RANGE_NOT_SATISFIABLE = 416;
const int EXPECTATION_FAILED = 417;
const int UNPROCESSABLE_ENTITY = 422;
const int LOCKED = 423;
const int FAILED_DEPENDENCY = 424;
const int PRECONDITION_REQUIRED = 428;
const int TOO_MANY_REQUESTS = 429;
const int REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
const int INTERNAL_SERVER_ERROR = 500;
const int NOT_IMPLEMENTED = 501;
const int BAD_GATEWAY = 502;
const int SERVICE_UNAVAILABLE = 503;
const int GATEWAY_TIMEOUT = 504;
const int HTTP_VERSION_NOT_SUPPORTED = 505;
const int INSUFFICIENT_STORAGE = 507;
const int LOOP_DETECTED = 508;
const int NOT_EXTENDED = 510;
const int NETWORK_AUTHENTICATION_REQUIRED = 511;
/**
* List of acceptable header types.
*
* @var \Titon\Http\HeaderList
*/
protected static HeaderList $headerTypes = Vector {
'Accept',
'Accept-Charset',
'Accept-Encoding',
'Accept-Language',
'Accept-Ranges',
'Access-Control-Allow-Origin',
'Age',
'Allow',
'Authentication-Info',
'Authorization',
'Cache-Control',
'Connection',
'Content-Disposition',
'Content-Encoding',
'Content-Language',
'Content-Length',
'Content-Location',
'Content-MD5',
'Content-Range',
'Content-Type',
'Cookie',
'Date',
'ETag',
'Expires',
'Expect',
'From',
'Host',
'If-Match',
'If-Modified-Since',
'If-None-Match',
'If-Range',
'If-Unmodified-Since',
'Keep-Alive',
'Last-Modified',
'Link',
'Location',
'Max-Forwards',
'Origin',
'P3P',
'Pragma',
'Proxy-Authenticate',
'Proxy-Authorization',
'Range',
'Referer',
'Refresh',
'Retry-After',
'Server',
'Set-Cookie',
'Status',
'Strict-Transport-Security',
'TE',
'Trailer',
'Transfer-Encoding',
'Upgrade',
'User-Agent',
'Vary',
'Via',
'Warning',
'WWW-Authenticate'
};
/**
* List of possible method types.
*
* @var \Titon\Http\MethodList
*/
protected static MethodList $methodTypes = Vector {
'GET',
'POST',
'PUT',
'DELETE',
'HEAD',
'TRACE',
'OPTIONS',
'CONNECT'
};
/**
* List of all available response status codes.
*
* @var \Titon\Http\StatusCodeMap
*/
protected static StatusCodeMap $statusCodes = Map {
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing', // RFC2518
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status', // RFC4918
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity', // RFC4918
423 => 'Locked', // RFC4918
424 => 'Failed Dependency', // RFC4918
428 => 'Precondition Required', // RFC6585
429 => 'Too Many Requests', // RFC6585
431 => 'Request Header Fields Too Large', // RFC6585
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
507 => 'Insufficient Storage', // RFC4918
508 => 'Loop Detected', // RFC5842
510 => 'Not Extended', // RFC2774
511 => 'Network Authentication Required', // RFC6585
};
/**
* Return all the standard types of HTTP headers.
*
* @return \Titon\Http\HeaderList
*/
public static function getHeaderTypes(): HeaderList {
return static::$headerTypes;
}
/**
* Return all the supported method types.
*
* @return \Titon\Http\MethodList
*/
public static function getMethodTypes(): MethodList {
return static::$methodTypes;
}
/**
* Get a single status code.
*
* @param int $code
* @return string
* @throws \Titon\Http\Exception\InvalidStatusException
*/
public static function getStatusCode(int $code): string {
if (static::$statusCodes->contains($code)) {
return static::$statusCodes[$code];
}
throw new InvalidStatusException(sprintf('Status code %s is not supported', $code));
}
/**
* Get all status codes.
*
* @return \Titon\Http\StatusCodeMap
*/
public static function getStatusCodes(): StatusCodeMap {
return static::$statusCodes;
}
}