Skip to content

Commit 6fa8387

Browse files
author
Kyra Farrow
committed
[HttpClient] fix dealing with 1xx informational responses
1 parent 7c05803 commit 6fa8387

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Response/CurlResponse.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,19 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
289289
// Regular header line: add it to the list
290290
self::addResponseHeaders([substr($data, 0, -2)], $info, $headers);
291291

292-
if (0 === strpos($data, 'HTTP') && 300 <= $info['http_code'] && $info['http_code'] < 400) {
292+
if (0 !== strpos($data, 'HTTP/')) {
293+
if (0 === stripos($data, 'Location:')) {
294+
$location = trim(substr($data, 9, -2));
295+
}
296+
297+
return \strlen($data);
298+
}
299+
300+
if (\function_exists('openssl_x509_read') && $certinfo = curl_getinfo($ch, CURLINFO_CERTINFO)) {
301+
$info['peer_certificate_chain'] = array_map('openssl_x509_read', array_column($certinfo, 'Cert'));
302+
}
303+
304+
if (300 <= $info['http_code'] && $info['http_code'] < 400) {
293305
if (curl_getinfo($ch, CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
294306
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
295307
} elseif (303 === $info['http_code'] || ('POST' === $info['http_method'] && \in_array($info['http_code'], [301, 302], true))) {
@@ -298,15 +310,14 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
298310
}
299311
}
300312

301-
if (0 === stripos($data, 'Location:')) {
302-
$location = trim(substr($data, 9, -2));
303-
}
304-
305313
return \strlen($data);
306314
}
307315

308316
// End of headers: handle redirects and add to the activity list
309-
$statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
317+
if (200 > $statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE)) {
318+
return \strlen($data);
319+
}
320+
310321
$info['redirect_url'] = null;
311322

312323
if (300 <= $statusCode && $statusCode < 400 && null !== $location) {
@@ -336,10 +347,6 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
336347
return 0;
337348
}
338349

339-
if (\function_exists('openssl_x509_read') && $certinfo = curl_getinfo($ch, CURLINFO_CERTINFO)) {
340-
$info['peer_certificate_chain'] = array_map('openssl_x509_read', array_column($certinfo, 'Cert'));
341-
}
342-
343350
curl_setopt($ch, CURLOPT_PRIVATE, 'content');
344351
} elseif (null !== $info['redirect_url'] && $logger) {
345352
$logger->info(sprintf('Redirecting: "%s %s"', $info['http_code'], $info['redirect_url']));

0 commit comments

Comments
 (0)