Skip to content

Commit f8dc2d4

Browse files
committed
StreamClient, CurlClient: fixed multiple line headers receiving [Ref #8]
1 parent 6ec1464 commit f8dc2d4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Github/Http/CurlClient.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,18 @@ protected function process(Request $request)
7272
CURLOPT_RETURNTRANSFER => TRUE,
7373
CURLOPT_POSTFIELDS => $request->getContent(),
7474
CURLOPT_HEADER => FALSE,
75-
CURLOPT_HEADERFUNCTION => function($curl, $line) use (& $responseHeaders) {
75+
CURLOPT_HEADERFUNCTION => function($curl, $line) use (& $responseHeaders, & $last) {
7676
if (strncasecmp($line, 'HTTP/', 5) === 0) {
7777
/** @todo Set proxy response as Response::setPrevious($proxyResponse)? */
7878
# The HTTP/x.y may occur multiple times with proxy (HTTP/1.1 200 Connection Established)
7979
$responseHeaders = [];
8080

81+
} elseif (in_array(substr($line, 0, 1), [' ', "\t"], TRUE)) {
82+
$responseHeaders[$last] .= ' ' . trim($line); # RFC2616, 2.2
83+
8184
} elseif ($line !== "\r\n") {
8285
list($name, $value) = explode(':', $line, 2);
83-
$responseHeaders[trim($name)] = trim($value);
86+
$responseHeaders[$last = trim($name)] = trim($value);
8487
}
8588

8689
return strlen($line);

src/Github/Http/StreamClient.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ protected function fileGetContents($url, array $contextOptions)
103103

104104
$headers = [];
105105
foreach ($http_response_header as $header) {
106-
list($name, $value) = explode(':', $header, 2) + [NULL, NULL];
107-
$headers[trim($name)] = trim($value);
106+
if (in_array(substr($header, 0, 1), [' ', "\t"], TRUE)) {
107+
$headers[$last] .= ' ' . trim($header); # RFC2616, 2.2
108+
} else {
109+
list($name, $value) = explode(':', $header, 2) + [NULL, NULL];
110+
$headers[$last = trim($name)] = trim($value);
111+
}
108112
}
109113

110114
return [$m[1], $headers, $content];

0 commit comments

Comments
 (0)