Skip to content

Setting and unsetting CURLOPT_NOBODY causes hang #5725

@causal-agent

Description

@causal-agent

Since curl 7.71.0, setting and unsetting CURLOPT_NOBODY causes the request following unsetting it to hang. This behaviour was introduced in 9c845be, which sets the request method to HEAD when CURLOPT_NOBODY is set, but does not change it away from HEAD when it is unset. Notably, this comment and the behaviour it describes was removed 9c845be#diff-8fb104c402dc51bdffef05a372f32aa2L4000

     /* ... but if unset there really is no perfect method that is the
        "opposite" of HEAD but in reality most people probably think GET
        then. The important thing is that we can't let it remain HEAD if the
        opt_no_body is set FALSE since then we'll behave wrong when getting
        HTTP. */

I did this

#include <curl/curl.h>
int main(void) {
	CURL *curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
	curl_easy_setopt(curl, CURLOPT_URL, "https://gentoo.org");
	curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
	curl_easy_perform(curl);
	curl_easy_setopt(curl, CURLOPT_NOBODY, 0L);
	curl_easy_perform(curl);
}

I expected the following

A HEAD request followed by a GET request (behaviour prior to 7.71.0). Instead, the second request is still a HEAD request, but curl waits to receive a body, causing a hang.

curl/libcurl version

curl 7.71.0 (amd64-portbld-freebsd12.1) libcurl/7.71.0 OpenSSL/1.1.1d zlib/1.2.11 nghttp2/1.41.0
Release-Date: 2020-06-24
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smtp smtps telnet tftp 
Features: alt-svc AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz NTLM NTLM_WB SPNEGO SSL TLS-SRP UnixSockets

operating system

FreeBSD [snip] 12.1-RELEASE-p7 FreeBSD 12.1-RELEASE-p7 GENERIC  amd64

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions