WWW::Curl::Easy hangs #334

Could be caused by payload in PUT/POST. During my tests of commits bd0ceae510 and  6812fa88c3 stopped working as soon as there was a payload (json in my case).
 Worked for me if payload was passed as file handler via CURLOPT_READDATA.
This commit is contained in:
Awalon 2022-03-21 01:30:18 +01:00
parent 6812fa88c3
commit 440a024bbd
No known key found for this signature in database
GPG key ID: 73C00BFA11FDC12E

View file

@ -2671,6 +2671,7 @@ sub fetch_via_curl {
$curl->setopt(WWW::Curl::Easy->CURLOPT_USERAGENT, "${program}/${version}");
$curl->setopt(WWW::Curl::Easy->CURLOPT_CONNECTTIMEOUT, $timeout);
$curl->setopt(WWW::Curl::Easy->CURLOPT_TIMEOUT, $timeout);
$curl->setopt(WWW::Curl::Easy->CURLOPT_VERBOSE, 1) if opt('verbose');
$curl->setopt(WWW::Curl::Easy->CURLOPT_POST, 1) if ($method eq 'POST');
$curl->setopt(WWW::Curl::Easy->CURLOPT_PUT, 1) if ($method eq 'PUT');
@ -2685,11 +2686,17 @@ sub fetch_via_curl {
@header_lines = split('\n', $headers);
$curl->setopt(WWW::Curl::Easy->CURLOPT_HTTPHEADER, \@header_lines);
}
# Add in the data if any was provided (for POST/PATCH)
my $fh;
if (my $datalen = length($data)) {
if ($method eq 'PUT') {
open ($fh, "<", \$data) or fatal("cannot open PUT data for reading: $!");
$curl->setopt(WWW::Curl::Easy->CURLOPT_READDATA, $fh);
} else {
# Add in the data if any was provided (for POST/PATCH)
$curl->setopt(WWW::Curl::Easy->CURLOPT_POSTFIELDS, ${data});
$curl->setopt(WWW::Curl::Easy->CURLOPT_POSTFIELDSIZE, $datalen);
}
}
$curl->setopt(WWW::Curl::Easy->CURLOPT_WRITEDATA,\$reply);
# don't include ${url} as that might expose login credentials
@ -2704,6 +2711,11 @@ sub fetch_via_curl {
warning("CURL error (%d) %s", $rc, $curl->strerror($rc));
debug($curl->errbuf);
}
close($fh) if defined($fh);
if ($method eq 'PUT') {
# remove continue section
$reply =~ s/^HTTP\/.*(HTTP\/)/$1/s if defined($reply);
}
} else {
# System does not have the WWW::Curl::Easy module so attempt with system Curl command
push(@curlopt, "silent");