From: Ian Jackson Date: Tue, 23 Jul 2019 16:26:51 +0000 (+0100) Subject: dgit: Reorganise url_fetch X-Git-Tag: archive/debian/9.6~8 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f9462701607b57a6debcf3e0e7a5548a56af3cf6;p=dgit.git dgit: Reorganise url_fetch This was archive_api_query_curl. We're working on making it good for other things too. No functional change. Signed-off-by: Ian Jackson --- diff --git a/dgit b/dgit index 5bd648a2..48be1987 100755 --- a/dgit +++ b/dgit @@ -1192,10 +1192,9 @@ sub cfg_apply_map ($$$) { $$varref = $_; } -#---------- `ftpmasterapi' archive query method (nascent) ---------- - -sub archive_api_query_curl ($) { - my ($url) = @_; +sub url_fetch ($;@) { + my ($url, %xopts) = @_; + # Ok404 => 1 means give undef for 404 use WWW::Curl::Easy; @@ -1220,7 +1219,7 @@ sub archive_api_query_curl ($) { } } - printdebug "archive api query: fetching $url...\n"; + printdebug "query: fetching $url...\n"; local $SIG{PIPE} = 'IGNORE'; @@ -1229,18 +1228,21 @@ sub archive_api_query_curl ($) { $url, $curl->strerror($x), $curl->errbuf if $x; - return $curl->getinfo(CURLINFO_HTTP_CODE), $response_body; + my $code = $curl->getinfo(CURLINFO_HTTP_CODE); + if ($code eq '404' && $xopts{Ok404}) { return undef; } + + fail f_ "fetch of %s gave HTTP code %s", $url, $code + unless $url =~ m#^file://# or $code =~ m/^2/; + return $response_body; } +#---------- `ftpmasterapi' archive query method (nascent) ---------- + sub api_query_raw ($;$) { my ($subpath, $ok404) = @_; my $url = access_cfg('archive-query-url'); $url .= $subpath; - my ($code,$json) = archive_api_query_curl($url); - return undef if $code eq '404' && $ok404; - fail f_ "fetch of %s gave HTTP code %s", $url, $code - unless $url =~ m#^file://# or $code =~ m/^2/; - return $json; + return url_fetch $url, Ok404 => $ok404; } sub api_query ($$;$) {