Description
Symfony version(s) affected: 5.0.11
I know my Symfony version is out of date and unsupported, but I can not upgrade yet. If this is fixed in a future version, please let me know as I could not find a similar ticket.
When using an HttpClient to post via a proxy, the debug portion of getInfo() does not get populated if the proxy returns any errors.
$response = $httpClient->request('POST', 'https://test.ac.za/uat/admission', $requestOptions);
dd($response->getInfo('debug'));
If the proxy does not return an error (and no exception is thrown), the debug is empty.
If however, I call getContent(), getHeaders() or getStatusCode() first, the debug info is present:
$response = $httpClient->request('POST', 'https://test.ac.za/uat/admission', $requestOptions);
$response->getStatusCode();
dd($response->getInfo('debug'));
debug info shows:
* Trying 172.17.89.51:8080...
* Connected to proxyserver (172.17.89.51) port 8080 (#0)
* allocate connect buffer!
* Establish HTTP proxy tunnel to test.ac.za:443
* Proxy auth using Basic with user 'XXXXX'
> CONNECT test.ac.za:443 HTTP/1.1
Host: test.ac.za:443
Proxy-Authorization: Basic XXXXXXXXXX==
Proxy-Connection: Keep-Alive
< HTTP/1.1 200 Connection established
* Proxy replied 200 to CONNECT request
* CONNECT phase completed!
..
..
This works fine in the proxy is working as expected. If not, $httpClient->request() throws an exception with the following message:
"Failure when receiving data from the peer for "https://test.ac.za/uat/admission"."
There is no way to find out what the real problem is with the proxy setting.
When I change the debugBuffer in CurlResponse to an actual file and tail that file, I can see what went wrong with the proxy but I found no way to retrieve that info via getInfo('debug') or any other way that allows me to fix the configuration issues with the proxy server.
$this->debugBuffer = fopen('c:\Temp\php.log', 'w+');
No credentials given:
* Trying 172.17.89.51:8080...
* Connected to proxyserver (172.17.89.51) port 8080 (#0)
* allocate connect buffer!
* Establish HTTP proxy tunnel to test.ac.za:443
> CONNECT test.ac.za:443 HTTP/1.1
Host: test.ac.za:443
Proxy-Connection: Keep-Alive
< HTTP/1.1 407 Proxy Authentication Required
< Server: squid
< Mime-Version: 1.0
< Date: Tue, 31 Aug 2021 09:57:07 GMT
< Content-Type: text/html;charset=utf-8
< Content-Length: 3670
< X-Squid-Error: ERR_CACHE_ACCESS_DENIED 0
< Vary: Accept-Language
< Content-Language: en
< Proxy-Authenticate: Negotiate
<
* Ignore 3670 bytes of response-body
* Received HTTP code 407 from proxy after CONNECT
* CONNECT phase completed!
* Closing connection 0
Incorrect port:
< HTTP/1.1 405 Method Not Allowed
< Date: Tue, 31 Aug 2021 10:17:39 GMT
< Server: Apache/2.4.6 (CentOS) PHP/5.4.16
< Allow: GET,HEAD,POST,OPTIONS
< Content-Length: 235
< Content-Type: text/html; charset=iso-8859-1
<
* Received HTTP code 405 from proxy after CONNECT
* CONNECT phase completed!
* Closing connection 0