|
5 | 5 | use Exception;
|
6 | 6 | use InvalidArgumentException;
|
7 | 7 | use RuntimeException;
|
8 |
| -use RingCentral\Psr7; |
9 | 8 | use React\Promise;
|
10 | 9 | use React\Promise\Deferred;
|
11 | 10 | use React\Socket\ConnectionInterface;
|
@@ -183,30 +182,31 @@ public function connect($uri)
|
183 | 182 | $fn = null;
|
184 | 183 |
|
185 | 184 | // try to parse headers as response message
|
186 |
| - try { |
187 |
| - $response = Psr7\parse_response(substr($buffer, 0, $pos)); |
188 |
| - } catch (Exception $e) { |
| 185 | + $start = strtok($buffer, "\r\n"); |
| 186 | + if (!$start || !preg_match('/^HTTP\/.* ([0-9]{3})( .*)?$/', $start, $matchs)) { |
189 | 187 | $deferred->reject(new RuntimeException(
|
190 | 188 | 'Connection to ' . $uri . ' failed because proxy returned invalid response (EBADMSG)',
|
191 |
| - defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71, |
192 |
| - $e |
| 189 | + defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71 |
193 | 190 | ));
|
194 | 191 | $stream->close();
|
195 | 192 | return;
|
196 | 193 | }
|
197 | 194 |
|
198 |
| - if ($response->getStatusCode() === 407) { |
| 195 | + $statusCode = (int) $matchs[1]; |
| 196 | + $reasonPhrase = isset($matchs[2]) ? trim($matchs[2]) : ''; |
| 197 | + |
| 198 | + if ($statusCode === 407) { |
199 | 199 | // map status code 407 (Proxy Authentication Required) to EACCES
|
200 | 200 | $deferred->reject(new RuntimeException(
|
201 |
| - 'Connection to ' . $uri . ' failed because proxy denied access with HTTP error code ' . $response->getStatusCode() . ' (' . $response->getReasonPhrase() . ') (EACCES)', |
| 201 | + 'Connection to ' . $uri . ' failed because proxy denied access with HTTP error code ' . $statusCode . ' (' . $reasonPhrase . ') (EACCES)', |
202 | 202 | defined('SOCKET_EACCES') ? SOCKET_EACCES : 13
|
203 | 203 | ));
|
204 | 204 | $stream->close();
|
205 | 205 | return;
|
206 |
| - } elseif ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { |
| 206 | + } elseif ($statusCode < 200 || $statusCode >= 300) { |
207 | 207 | // map non-2xx status code to ECONNREFUSED
|
208 | 208 | $deferred->reject(new RuntimeException(
|
209 |
| - 'Connection to ' . $uri . ' failed because proxy refused connection with HTTP error code ' . $response->getStatusCode() . ' (' . $response->getReasonPhrase() . ') (ECONNREFUSED)', |
| 209 | + 'Connection to ' . $uri . ' failed because proxy refused connection with HTTP error code ' . $statusCode . ' (' . $reasonPhrase . ') (ECONNREFUSED)', |
210 | 210 | defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
|
211 | 211 | ));
|
212 | 212 | $stream->close();
|
|
0 commit comments