From 440a024bbd92b670daef8209897dcae6708ba1a0 Mon Sep 17 00:00:00 2001 From: Awalon Date: Mon, 21 Mar 2022 01:30:18 +0100 Subject: [PATCH] WWW::Curl::Easy hangs #334 Could be caused by payload in PUT/POST. During my tests of commits bd0ceae51046bc6ce457e9d61752b848339937b0 and 6812fa88c30fea95fc0e9192f9694f11e78fb4e5 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. --- ddclient.in | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ddclient.in b/ddclient.in index 38cb8da..66719d8 100755 --- a/ddclient.in +++ b/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");