Skip to content

Commit c8c42e8

Browse files
committed
Remove ringcentral/psr7 because it appears to be abandoned and upstream projects would like to support psr/http-message ^2.0
1 parent 7353a03 commit c8c42e8

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"require": {
1414
"php": ">=5.3",
1515
"react/promise": "^3.2 || ^2.1 || ^1.2.1",
16-
"react/socket": "^1.16",
17-
"ringcentral/psr7": "^1.2"
16+
"react/socket": "^1.16"
1817
},
1918
"require-dev": {
2019
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",

src/ProxyConnector.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Exception;
66
use InvalidArgumentException;
77
use RuntimeException;
8-
use RingCentral\Psr7;
98
use React\Promise;
109
use React\Promise\Deferred;
1110
use React\Socket\ConnectionInterface;
@@ -183,30 +182,31 @@ public function connect($uri)
183182
$fn = null;
184183

185184
// 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)) {
189187
$deferred->reject(new RuntimeException(
190188
'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
193190
));
194191
$stream->close();
195192
return;
196193
}
197194

198-
if ($response->getStatusCode() === 407) {
195+
$statusCode = (int) $matchs[1];
196+
$reasonPhrase = isset($matchs[2]) ? trim($matchs[2]) : '';
197+
198+
if ($statusCode === 407) {
199199
// map status code 407 (Proxy Authentication Required) to EACCES
200200
$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)',
202202
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13
203203
));
204204
$stream->close();
205205
return;
206-
} elseif ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
206+
} elseif ($statusCode < 200 || $statusCode >= 300) {
207207
// map non-2xx status code to ECONNREFUSED
208208
$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)',
210210
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
211211
));
212212
$stream->close();

0 commit comments

Comments
 (0)