Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jun 2014 20:27:16 +0000 (UTC)
From:      Dag-Erling Smørgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r267127 - head/lib/libfetch
Message-ID:  <201406052027.s55KRGlA064455@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Thu Jun  5 20:27:16 2014
New Revision: 267127
URL: http://svnweb.freebsd.org/changeset/base/267127

Log:
  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

Modified:
  head/lib/libfetch/fetch.3
  head/lib/libfetch/http.c

Modified: head/lib/libfetch/fetch.3
==============================================================================
--- head/lib/libfetch/fetch.3	Thu Jun  5 19:38:44 2014	(r267126)
+++ head/lib/libfetch/fetch.3	Thu Jun  5 20:27:16 2014	(r267127)
@@ -627,6 +627,7 @@ the document URL will be used as referre
 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

Modified: head/lib/libfetch/http.c
==============================================================================
--- head/lib/libfetch/http.c	Thu Jun  5 19:38:44 2014	(r267126)
+++ head/lib/libfetch/http.c	Thu Jun  5 20:27:16 2014	(r267127)
@@ -1683,10 +1683,15 @@ http_request(struct url *URL, const char
 			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");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406052027.s55KRGlA064455>