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
This commit is contained in:
Dag-Erling Smørgrav 2014-06-05 20:27:16 +00:00
parent c835c70600
commit c257f99e9b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=267127
2 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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");