|
3 | 3 | namespace WpOrg\Requests\Tests\Fixtures; |
4 | 4 |
|
5 | 5 | use WpOrg\Requests\Transport; |
| 6 | +use WpOrg\Requests\Utility\HttpStatus; |
6 | 7 |
|
7 | 8 | final class TransportMock implements Transport { |
8 | 9 | public $code = 200; |
9 | 10 | public $chunked = false; |
10 | 11 | public $body = 'Test Body'; |
11 | 12 | public $raw_headers = ''; |
12 | 13 |
|
13 | | - private static $messages = [ |
14 | | - 100 => '100 Continue', |
15 | | - 101 => '101 Switching Protocols', |
16 | | - 200 => '200 OK', |
17 | | - 201 => '201 Created', |
18 | | - 202 => '202 Accepted', |
19 | | - 203 => '203 Non-Authoritative Information', |
20 | | - 204 => '204 No Content', |
21 | | - 205 => '205 Reset Content', |
22 | | - 206 => '206 Partial Content', |
23 | | - 300 => '300 Multiple Choices', |
24 | | - 301 => '301 Moved Permanently', |
25 | | - 302 => '302 Found', |
26 | | - 303 => '303 See Other', |
27 | | - 304 => '304 Not Modified', |
28 | | - 305 => '305 Use Proxy', |
29 | | - 306 => '306 (Unused)', |
30 | | - 307 => '307 Temporary Redirect', |
31 | | - 400 => '400 Bad Request', |
32 | | - 401 => '401 Unauthorized', |
33 | | - 402 => '402 Payment Required', |
34 | | - 403 => '403 Forbidden', |
35 | | - 404 => '404 Not Found', |
36 | | - 405 => '405 Method Not Allowed', |
37 | | - 406 => '406 Not Acceptable', |
38 | | - 407 => '407 Proxy Authentication Required', |
39 | | - 408 => '408 Request Timeout', |
40 | | - 409 => '409 Conflict', |
41 | | - 410 => '410 Gone', |
42 | | - 411 => '411 Length Required', |
43 | | - 412 => '412 Precondition Failed', |
44 | | - 413 => '413 Request Entity Too Large', |
45 | | - 414 => '414 Request-URI Too Long', |
46 | | - 415 => '415 Unsupported Media Type', |
47 | | - 416 => '416 Requested Range Not Satisfiable', |
48 | | - 417 => '417 Expectation Failed', |
49 | | - 418 => '418 I\'m a teapot', |
50 | | - 428 => '428 Precondition Required', |
51 | | - 429 => '429 Too Many Requests', |
52 | | - 431 => '431 Request Header Fields Too Large', |
53 | | - 500 => '500 Internal Server Error', |
54 | | - 501 => '501 Not Implemented', |
55 | | - 502 => '502 Bad Gateway', |
56 | | - 503 => '503 Service Unavailable', |
57 | | - 504 => '504 Gateway Timeout', |
58 | | - 505 => '505 HTTP Version Not Supported', |
59 | | - 511 => '511 Network Authentication Required', |
60 | | - ]; |
61 | | - |
62 | 14 | public function request($url, $headers = [], $data = [], $options = []) { |
63 | | - $status = isset(self::$messages[$this->code]) ? self::$messages[$this->code] : $this->code . ' unknown'; |
64 | | - $response = "HTTP/1.0 $status\r\n"; |
| 15 | + $text = HttpStatus::is_valid_code($this->code) ? HttpStatus::get_text($this->code) : 'unknown'; |
| 16 | + $response = "HTTP/1.0 {$this->code} {$text}\r\n"; |
65 | 17 | $response .= "Content-Type: text/plain\r\n"; |
66 | 18 | if ($this->chunked) { |
67 | 19 | $response .= "Transfer-Encoding: chunked\r\n"; |
|
0 commit comments