8000 [HttpClient] CurlHttpClient HEAD request hangs · Issue #34102 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[HttpClient] CurlHttpClient HEAD request hangs #34102
Closed
@rscipien

Description

@rscipien

Symfony version(s) affected: 4.3.3

Description
Use HttpClientInterface::request with $method param set to HEAD
Depending on installed curl version request hangs.
Not working with curl

curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

How to reproduce

    /**
    * @var HttpClientInterface
    */
    private $client;
    
    /**
     * Constructor.
     *
     * @param HttpClientInterface $client
     */
    public function __construct(HttpClientInterface $client)
    {
        $this->client = $client;
    }

   public function test()
   {
       $this->client->request('HEAD', 'some/url');
   }

Possible Solution
Change code in Symfony\Component\HttpClient\CurlHttpClient::request. For HEAD http metohd use $curlopts[CURLOPT_NOBODY] = 1;

if ('POST' === $method) {
            // Use CURLOPT_POST to have browser-like POST-to-GET redirects for 301, 302 and 303
            $curlopts[CURLOPT_POST] = true;
//        } elseif ('HEAD' === $method) {
//            $curlopts[CURLOPT_NOBODY] = 1;
        } else {
            $curlopts[CURLOPT_CUSTOMREQUEST] = $method;
        }

Additional context

https://curl.haxx.se/docs/manpage.html#-X
https://stackoverflow.com/a/770200

This option only changes the actual word used in the HTTP request, it does not alter the way curl behaves. So for example if you want to make a proper HEAD request, using -X HEAD will not suffice. You need to use the -I, --head option. 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0