Skip to content

Commit 9e131ab

Browse files
committed
Merge branch 'refs/heads/replace-guzzle-http' into 0.3
Conflicts: composer.lock
2 parents 72799ef + 1abef74 commit 9e131ab

File tree

3 files changed

+96
-7
lines changed

3 files changed

+96
-7
lines changed

Response.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace React\Http;
44

55
use Evenement\EventEmitter;
6-
use Guzzle\Http\Message\Response as GuzzleResponse;
76
use React\Socket\ConnectionInterface;
87
use React\Stream\WritableStreamInterface;
98

@@ -59,18 +58,37 @@ public function writeHead($status = 200, array $headers = array())
5958
$this->chunkedEncoding = false;
6059
}
6160

62-
$response = new GuzzleResponse($status);
63-
$response->setHeader('X-Powered-By', 'React/alpha');
64-
$response->addHeaders($headers);
61+
$headers = array_merge(
62+
array('X-Powered-By' => 'React/alpha'),
63+
$headers
64+
);
6565
if ($this->chunkedEncoding) {
66-
$response->setHeader('Transfer-Encoding', 'chunked');
66+
$headers['Transfer-Encoding'] = 'chunked';
6767
}
68-
$data = (string) $response;
68+
69+
$data = $this->formatHead($status, $headers);
6970
$this->conn->write($data);
7071

7172
$this->headWritten = true;
7273
}
7374

75+
private function formatHead($status, array $headers)
76+
{
77+
$status = (int) $status;
78+
$text = isset(ResponseCodes::$statusTexts[$status]) ? ResponseCodes::$statusTexts[$status] : '';
79+
$data = "HTTP/1.1 $status $text\r\n";
80+
81+
foreach ($headers as $name => $value) {
82+
$name = str_replace(array("\r", "\n"), '', $name);
83+
$value = str_replace(array("\r", "\n"), '', $value);
84+
85+
$data .= "$name: $value\r\n";
86+
}
87+
$data .= "\r\n";
88+
89+
return $data;
90+
}
91+
7492
public function write($data)
7593
{
7694
if (!$this->headWritten) {

ResponseCodes.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace React\Http;
4+
5+
/**
6+
* This is copy-pasted from Symfony2's Response class
7+
*/
8+
class ResponseCodes
9+
{
10+
public static $statusTexts = array(
11+
100 => 'Continue',
12+
101 => 'Switching Protocols',
13+
102 => 'Processing', // RFC2518
14+
200 => 'OK',
15+
201 => 'Created',
16+
202 => 'Accepted',
17+
203 => 'Non-Authoritative Information',
18+
204 => 'No Content',
19+
205 => 'Reset Content',
20+
206 => 'Partial Content',
21+
207 => 'Multi-Status', // RFC4918
22+
208 => 'Already Reported', // RFC5842
23+
226 => 'IM Used', // RFC3229
24+
300 => 'Multiple Choices',
25+
301 => 'Moved Permanently',
26+
302 => 'Found',
27+
303 => 'See Other',
28+
304 => 'Not Modified',
29+
305 => 'Use Proxy',
30+
306 => 'Reserved',
31+
307 => 'Temporary Redirect',
32+
308 => 'Permanent Redirect', // RFC-reschke-http-status-308-07
33+
400 => 'Bad Request',
34+
401 => 'Unauthorized',
35+
402 => 'Payment Required',
36+
403 => 'Forbidden',
37+
404 => 'Not Found',
38+
405 => 'Method Not Allowed',
39+
406 => 'Not Acceptable',
40+
407 => 'Proxy Authentication Required',
41+
408 => 'Request Timeout',
42+
409 => 'Conflict',
43+
410 => 'Gone',
44+
411 => 'Length Required',
45+
412 => 'Precondition Failed',
46+
413 => 'Request Entity Too Large',
47+
414 => 'Request-URI Too Long',
48+
415 => 'Unsupported Media Type',
49+
416 => 'Requested Range Not Satisfiable',
50+
417 => 'Expectation Failed',
51+
418 => 'I\'m a teapot', // RFC2324
52+
422 => 'Unprocessable Entity', // RFC4918
53+
423 => 'Locked', // RFC4918
54+
424 => 'Failed Dependency', // RFC4918
55+
425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817
56+
426 => 'Upgrade Required', // RFC2817
57+
428 => 'Precondition Required', // RFC6585
58+
429 => 'Too Many Requests', // RFC6585
59+
431 => 'Request Header Fields Too Large', // RFC6585
60+
500 => 'Internal Server Error',
61+
501 => 'Not Implemented',
62+
502 => 'Bad Gateway',
63+
503 => 'Service Unavailable',
64+
504 => 'Gateway Timeout',
65+
505 => 'HTTP Version Not Supported',
66+
506 => 'Variant Also Negotiates (Experimental)', // RFC2295
67+
507 => 'Insufficient Storage', // RFC4918
68+
508 => 'Loop Detected', // RFC5842
69+
510 => 'Not Extended', // RFC2774
70+
511 => 'Network Authentication Required', // RFC6585
71+
);
72+
}

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"license": "MIT",
66
"require": {
77
"php": ">=5.3.3",
8-
"guzzle/http": "3.0.*",
98
"guzzle/parser": "3.0.*",
109
"react/socket": "0.3.*"
1110
},

0 commit comments

Comments
 (0)