nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 298 forks source link

Proxy CONNECT aborted #269

Open akramfares opened 6 years ago

akramfares commented 6 years ago

Hello,

I'm trying to send a simple POST request: $client->request("POST", $payload(), $uri, "application/json", 3);

But I get this error:

Proxy CONNECT aborted

I'm using docker (with proxy), and after debugging, I found out that Httpful is adding Content-Length to the header which is causing this issue:

// vendor/nategood/httpful/src/Httpful/Request.php in line 898
// set Content-Length to the size of the payload if present
        if (isset($this->payload)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->serialized_payload);
            if (!$this->isUpload()) {
                $this->headers['Content-Length'] =
                    $this->_determineLength($this->serialized_payload);
            }
        }

The complete debug log when running curl:

* Hostname was NOT found in DNS cache
*   Trying xx.xx.xx.xx...
* Connected to proxy..com (xx.xx.xx.xx) port 8080 (#0)
* Establish HTTP proxy tunnel to website.com:443
* Proxy auth using Basic with user 'user'
* Server auth using Basic with user 'user2'
> CONNECT website.com:443 HTTP/1.1
> Host: website.com:443
> Proxy-Authorization: Basic hash
> User-Agent: curl
> Proxy-Connection: Keep-Alive
> Accept: application/json; version=3
> Content-Type: application/json
> Content-Length: 123
>
* Proxy CONNECT aborted
* Connection #0 to host proxy.com left intact
curl: (56) Proxy CONNECT aborted