summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2014-08-24 14:04:20 +0000
committerdes <des@FreeBSD.org>2014-08-24 14:04:20 +0000
commitdb46c7fe73eae40070a92ea983f59165139609e5 (patch)
treee9df38a669befc1b318151d5e50f5a3c1a2040a9
parent06c16a37047772858745f3a270998e02b1dafc05 (diff)
downloadFreeBSD-src-db46c7fe73eae40070a92ea983f59165139609e5.zip
FreeBSD-src-db46c7fe73eae40070a92ea983f59165139609e5.tar.gz
MFH (r267127): don't send User-Agent if HTTP_USER_AGENT is empty
-rw-r--r--lib/libfetch/fetch.31
-rw-r--r--lib/libfetch/http.c13
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/libfetch/fetch.3 b/lib/libfetch/fetch.3
index 6b2e4c0..0a83a35 100644
--- a/lib/libfetch/fetch.3
+++ b/lib/libfetch/fetch.3
@@ -627,6 +627,7 @@ the document URL will be used as referrer URL.
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 user agents.
+If defined but empty, no User-Agent header is sent.
.It Ev NETRC
Specifies a file to use instead of
.Pa ~/.netrc
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index 90790de..ad4a419 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -1693,10 +1693,15 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
else
http_cmd(conn, "Referer: %s", p);
}
- if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0')
- http_cmd(conn, "User-Agent: %s", p);
- else
- http_cmd(conn, "User-Agent: %s " _LIBFETCH_VER, getprogname());
+ if ((p = getenv("HTTP_USER_AGENT")) != NULL) {
+ /* no User-Agent if defined but empty */
+ if (*p != '\0')
+ http_cmd(conn, "User-Agent: %s", p);
+ } else {
+ /* default User-Agent */
+ http_cmd(conn, "User-Agent: %s " _LIBFETCH_VER,
+ getprogname());
+ }
if (url->offset > 0)
http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
http_cmd(conn, "Connection: close");
OpenPOWER on IntegriCloud