Skip to content

Commit 510bc17

Browse files
committedMay 11, 2017
Add an option for extending the user agent header
This is useful e.g. for distinguishing traffic to a binary cache (e.g. certain machines can use a different tag in the user agent).
1 parent 62d476c commit 510bc17

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎src/libstore/download.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ struct CurlDownloader : public Downloader
220220
curl_easy_setopt(req, CURLOPT_URL, request.uri.c_str());
221221
curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1L);
222222
curl_easy_setopt(req, CURLOPT_NOSIGNAL, 1);
223-
curl_easy_setopt(req, CURLOPT_USERAGENT, ("curl/" LIBCURL_VERSION " Nix/" + nixVersion).c_str());
223+
curl_easy_setopt(req, CURLOPT_USERAGENT,
224+
("curl/" LIBCURL_VERSION " Nix/" + nixVersion +
225+
(settings.userAgentSuffix != "" ? " " + settings.userAgentSuffix.get() : "")).c_str());
224226
#if LIBCURL_VERSION_NUM >= 0x072b00
225227
curl_easy_setopt(req, CURLOPT_PIPEWAIT, 1);
226228
#endif

‎src/libstore/globals.hh

+3
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ public:
318318

319319
Setting<unsigned long> connectTimeout{this, 0, "connect-timeout",
320320
"Timeout for connecting to servers during downloads. 0 means use curl's builtin default."};
321+
322+
Setting<std::string> userAgentSuffix{this, "", "user-agent-suffix",
323+
"String appended to the user agent in HTTP requests."};
321324
};
322325

323326

0 commit comments

Comments
 (0)
Please sign in to comment.