From 6a0cf64bce349bbe8de9a76bdda1b7b31010cf86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Sun, 27 May 2001 11:00:36 +0000 Subject: [PATCH] Implement a HTTP_USER_AGENT environment variable. PR: 27669 Submitted by: Eoin Lawless --- lib/libfetch/fetch.3 | 4 ++++ lib/libfetch/http.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/libfetch/fetch.3 b/lib/libfetch/fetch.3 index c4d60a4a435..4534d646b8b 100644 --- a/lib/libfetch/fetch.3 +++ b/lib/libfetch/fetch.3 @@ -512,6 +512,10 @@ variable. This variable is used if and only if connected to an HTTP proxy, and is ignored if a user and/or a password were specified in the proxy URL. +.It Ev HTTP_USER_AGENT +Specifies the User-Agent string to use for HTTP requests. +This can be useful when working with HTTP origin or proxy servers that +differentiate between usder agents. .El .Sh SEE ALSO .Xr fetch 1 , diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index 77c3a2d62cb..5863c80b62c 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -777,7 +777,10 @@ _http_request(struct url *URL, const char *op, struct url_stat *us, } /* other headers */ - _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); + if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0') + _http_cmd(fd, "User-Agent: %s", p); + else + _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); if (url->offset) _http_cmd(fd, "Range: bytes=%lld-", url->offset); _http_cmd(fd, "Connection: close");