From 119d72ad944a84a6ef709c15c5b1adb554a43c22 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Mon, 19 Jul 2021 11:57:19 +0200 Subject: [PATCH] fetchurl: User-Agent header and HTTP response code I discovered thinkbroadband.com requires the User-Agent header field and rejects requests missing it with HTTP response code 403 "access to the requested resource is forbidden". Now, fetchurl always adds the User-Agent header fetchurl/LIBCURL_VERSION. Also the error message now contains the HTTP response code. --- repos/libports/src/app/fetchurl/component.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/repos/libports/src/app/fetchurl/component.cc b/repos/libports/src/app/fetchurl/component.cc index d298e7005b..eacb93febb 100644 --- a/repos/libports/src/app/fetchurl/component.cc +++ b/repos/libports/src/app/fetchurl/component.cc @@ -276,12 +276,17 @@ struct Fetchurl::Main curl_easy_setopt(_curl, CURLOPT_PROXY, _fetch.proxy.string()); } + curl_easy_setopt(_curl, CURLOPT_USERAGENT, "fetchurl/" LIBCURL_VERSION); + CURLcode res = curl_easy_perform(_curl); close(_fetch.fd); _fetch.fd = -1; - if (res != CURLE_OK) - Genode::error(curl_easy_strerror(res), ", failed to fetch ", _fetch.url); + if (res != CURLE_OK) { + unsigned long response_code = -1; + curl_easy_getinfo(_curl, CURLINFO_RESPONSE_CODE, &response_code); + Genode::error(curl_easy_strerror(res), " (code=", response_code, "), failed to fetch ", _fetch.url); + } return res; }