WWW::Curl::Easy hangs #334
Could be caused by payload in PUT/POST. During my tests of commitsbd0ceae510and6812fa88c3stopped 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:
parent
6812fa88c3
commit
440a024bbd
1 changed files with 13 additions and 1 deletions
14
ddclient.in
14
ddclient.in
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue