summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2014-06-05 20:27:16 +0000
committerdes <des@FreeBSD.org>2014-06-05 20:27:16 +0000
commit055be14e5cf36c2dd7b4dcd5457fdaf8c6edb2f7 (patch)
tree3b18ae8a5a7ff67e34ec08986a9202fa9a8326c8 /lib
parentabe8dedcc84ee464fe37cbfce6e981d7a6b7044a (diff)
downloadFreeBSD-src-055be14e5cf36c2dd7b4dcd5457fdaf8c6edb2f7.zip
FreeBSD-src-055be14e5cf36c2dd7b4dcd5457fdaf8c6edb2f7.tar.gz
If HTTP_USER_AGENT is defined but empty, don't send User-Agent at all.
PR: 184507 Submitted by: jbeich@tormail.org (with modifications) MFC after: 1 week
Diffstat (limited to 'lib')
-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 cbbb8a8..983936c 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -1683,10 +1683,15 @@ http_request(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