Skip to content

Commit 89dd5ff

Browse files
committed
Http: fix proxy HTTP response [Ref #5]
When SSL request goes throuh the HTTP proxy, proxy uses CONNECT and adds 'HTTP/1.x 200 Connection Established' (and sometimes some headers like Proxy-Agent) before remote response. StreamClient isn't affected.
1 parent 151b8f7 commit 89dd5ff

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/Github/Http/CurlClient.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function process(Request $request)
5353
$headers[] = "$name: $value";
5454
}
5555

56-
$responseHeaders = NULL;
56+
$responseHeaders = [];
5757

5858
$softOptions = [
5959
CURLOPT_CONNECTTIMEOUT => 10,
@@ -74,9 +74,10 @@ protected function process(Request $request)
7474
CURLOPT_POSTFIELDS => $request->getContent(),
7575
CURLOPT_HEADER => FALSE,
7676
CURLOPT_HEADERFUNCTION => function($curl, $line) use (& $responseHeaders) {
77-
if ($responseHeaders === NULL) {
77+
if (strncasecmp($line, 'HTTP/', 5) === 0) {
78+
/** @todo Set proxy response as Response::setPrevious($proxyResponse)? */
79+
# The HTTP/x.y may occur multiple times with proxy (HTTP/1.1 200 Connection Established)
7880
$responseHeaders = [];
79-
# and skip 1st line, it is HTTP code
8081

8182
} elseif ($line !== "\r\n") {
8283
list($name, $value) = explode(':', $line, 2);
@@ -99,16 +100,11 @@ protected function process(Request $request)
99100
throw new BadResponseException('Setting cURL options failed: ' . curl_error($this->curl), curl_errno($this->curl));
100101
}
101102

102-
$responseHeaders = NULL;
103103
$content = curl_exec($this->curl);
104104
if ($content === FALSE) {
105105
throw new BadResponseException(curl_error($this->curl), curl_errno($this->curl));
106106
}
107107

108-
if (!is_array($responseHeaders)) {
109-
throw new BadResponseException('Response headers were not fetched.');
110-
}
111-
112108
$code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
113109
if ($code === FALSE) {
114110
throw new BadResponseException('HTTP status code is missing:' . curl_error($this->curl), curl_errno($this->curl));

0 commit comments

Comments
 (0)