about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-05-11T13·09+0200
committerEelco Dolstra <edolstra@gmail.com>2017-05-11T13·10+0200
commit510bc1735b3507b0f434303fdec5e824c879c838 (patch)
tree2fdc36553cf45856900c01a1064c688caef37e32 /src
parent62d476c7ee5dbb79fb435895e0cda3fac8f53ba3 (diff)
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).
Diffstat (limited to 'src')
-rw-r--r--src/libstore/download.cc4
-rw-r--r--src/libstore/globals.hh3
2 files changed, 6 insertions, 1 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 5390bdbf5ed8..dc1a3d94f74f 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -220,7 +220,9 @@ struct CurlDownloader : public Downloader
             curl_easy_setopt(req, CURLOPT_URL, request.uri.c_str());
             curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1L);
             curl_easy_setopt(req, CURLOPT_NOSIGNAL, 1);
-            curl_easy_setopt(req, CURLOPT_USERAGENT, ("curl/" LIBCURL_VERSION " Nix/" + nixVersion).c_str());
+            curl_easy_setopt(req, CURLOPT_USERAGENT,
+                ("curl/" LIBCURL_VERSION " Nix/" + nixVersion +
+                    (settings.userAgentSuffix != "" ? " " + settings.userAgentSuffix.get() : "")).c_str());
             #if LIBCURL_VERSION_NUM >= 0x072b00
             curl_easy_setopt(req, CURLOPT_PIPEWAIT, 1);
             #endif
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 7295b0d30af0..af37ec61d7a1 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -318,6 +318,9 @@ public:
 
     Setting<unsigned long> connectTimeout{this, 0, "connect-timeout",
         "Timeout for connecting to servers during downloads. 0 means use curl's builtin default."};
+
+    Setting<std::string> userAgentSuffix{this, "", "user-agent-suffix",
+        "String appended to the user agent in HTTP requests."};
 };