summaryrefslogtreecommitdiff
path: root/methods/http.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-03-25 17:31:12 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-04-09 10:39:34 +0200
commit29a79857c3cb53a94007bb7887234d2fe27850b2 (patch)
tree67ac753d391c7277068f177d45fc109cf932734d /methods/http.cc
parentd3133f92205e06f1f04e39c7e74db9efb98df19f (diff)
ubuntu: http: Add non-interactive to user agent if run by systemd
Include that apt is being run from a service in the user agent, so traffic can be analysed for interactive vs non-interactive use, and prioritised accordingly. It looks like this now: User-Agent: Debian APT-HTTP/1.3 (2.0.1) non-interactive A previous version included the full service names, but this raised some privacy concerns. LP: #1825000
Diffstat (limited to 'methods/http.cc')
-rw-r--r--methods/http.cc20
1 files changed, 19 insertions, 1 deletions
diff --git a/methods/http.cc b/methods/http.cc
index bd866d321..71aa56751 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -45,6 +45,10 @@
#include "http.h"
#include <apti18n.h>
+
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-login.h>
+#endif
/*}}}*/
using namespace std;
@@ -972,7 +976,21 @@ void HttpMethod::SendReq(FetchItem *Itm)
<< Base64Encode(Uri.User + ":" + Uri.Password) << "\r\n";
Req << "User-Agent: " << ConfigFind("User-Agent",
- "Debian APT-HTTP/1.3 (" PACKAGE_VERSION ")") << "\r\n";
+ "Debian APT-HTTP/1.3 (" PACKAGE_VERSION ")");
+
+#ifdef HAVE_SYSTEMD
+ char *unit = nullptr;
+ sd_pid_get_unit(getpid(), &unit);
+ if (unit != nullptr && *unit != '\0' && not APT::String::Startswith(unit, "user@") // user@ _is_ interactive
+ && unit != "packagekit.service"s // packagekit likely is interactive
+ && unit != "dbus.service"s // aptdaemon and qapt don't have systemd services
+ && ConfigFindB("User-Agent-Non-Interactive", false))
+ Req << " non-interactive";
+
+ free(unit);
+#endif
+
+ Req << "\r\n";
// the famously typoed HTTP header field
auto const referrer = ConfigFind("Referer", "");