[go] net/http: change default user agent string

666 views
Skip to first unread message

Aamir Khan (Gerrit)

unread,
Apr 27, 2015, 9:31:53 AM4/27/15
to Ian Lance Taylor, golang-co...@googlegroups.com
Aamir Khan uploaded a change:
https://go-review.googlesource.com/9385

net/http: change default user agent string

Default user agent in use - "Go 1.1 package http" doesn't conform to RFC
7231.
See http://tools.ietf.org/html/rfc7231#section-5.5.3

Use a valid user-agent string instead, including actual go version being
used.

Fixes #9792

Change-Id: I80249709800dcdbf6f2e97a63fab05656898e6aa
---
M src/net/http/httputil/dump_test.go
M src/net/http/request.go
M src/net/http/requestwrite_test.go
3 files changed, 28 insertions(+), 31 deletions(-)



diff --git a/src/net/http/httputil/dump_test.go
b/src/net/http/httputil/dump_test.go
index 024ee5a..0360e13 100644
--- a/src/net/http/httputil/dump_test.go
+++ b/src/net/http/httputil/dump_test.go
@@ -71,7 +71,7 @@

WantDumpOut: "GET /foo HTTP/1.1\r\n" +
"Host: example.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Accept-Encoding: gzip\r\n\r\n",
},

@@ -83,7 +83,7 @@

WantDumpOut: "GET /foo HTTP/1.1\r\n" +
"Host: example.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Accept-Encoding: gzip\r\n\r\n",
},

@@ -105,7 +105,7 @@

WantDumpOut: "POST / HTTP/1.1\r\n" +
"Host: post.tld\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Content-Length: 6\r\n" +
"Accept-Encoding: gzip\r\n\r\n",

@@ -130,7 +130,7 @@

WantDumpOut: "POST / HTTP/1.1\r\n" +
"Host: post.tld\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Content-Length: 8193\r\n" +
"Accept-Encoding: gzip\r\n\r\n" +
strings.Repeat("a", 8193),
diff --git a/src/net/http/request.go b/src/net/http/request.go
index a4e515c..49d57ba 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -19,6 +19,7 @@
"mime/multipart"
"net/textproto"
"net/url"
+ "runtime"
"strconv"
"strings"
"sync"
@@ -325,12 +326,7 @@
return def
}

-// NOTE: This is not intended to reflect the actual Go version being used.
-// It was changed from "Go http package" to "Go 1.1 package http" at the
-// time of the Go 1.1 release because the former User-Agent had ended up
-// on a blacklist for some intrusion detection systems.
-// See https://codereview.appspot.com/7532043.
-const defaultUserAgent = "Go 1.1 package http"
+var defaultUserAgent = "Go-http-client/" + runtime.Version()

// Write writes an HTTP/1.1 request -- header and body -- in wire format.
// This method consults the following fields of the request:
diff --git a/src/net/http/requestwrite_test.go
b/src/net/http/requestwrite_test.go
index e9a5f5f..15fc9a8 100644
--- a/src/net/http/requestwrite_test.go
+++ b/src/net/http/requestwrite_test.go
@@ -11,6 +11,7 @@
"io"
"io/ioutil"
"net/url"
+ "runtime"
"strings"
"testing"
)
@@ -93,13 +94,13 @@

WantWrite: "GET /search HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Transfer-Encoding: chunked\r\n\r\n" +
chunk("abcdef") + chunk(""),

WantProxy: "GET http://www.google.com/search HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Transfer-Encoding: chunked\r\n\r\n" +
chunk("abcdef") + chunk(""),
},
@@ -123,14 +124,14 @@

WantWrite: "POST /search HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Connection: close\r\n" +
"Transfer-Encoding: chunked\r\n\r\n" +
chunk("abcdef") + chunk(""),

WantProxy: "POST http://www.google.com/search HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Connection: close\r\n" +
"Transfer-Encoding: chunked\r\n\r\n" +
chunk("abcdef") + chunk(""),
@@ -156,7 +157,7 @@

WantWrite: "POST /search HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Connection: close\r\n" +
"Content-Length: 6\r\n" +
"\r\n" +
@@ -164,7 +165,7 @@

WantProxy: "POST http://www.google.com/search HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Connection: close\r\n" +
"Content-Length: 6\r\n" +
"\r\n" +
@@ -187,14 +188,14 @@

WantWrite: "POST / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Content-Length: 6\r\n" +
"\r\n" +
"abcdef",

WantProxy: "POST http://example.com/ HTTP/1.1\r\n" +
"Host: example.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Content-Length: 6\r\n" +
"\r\n" +
"abcdef",
@@ -210,7 +211,7 @@

WantWrite: "GET /search HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"\r\n",
},

@@ -232,13 +233,13 @@
// Also, nginx expects it for POST and PUT.
WantWrite: "POST / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Content-Length: 0\r\n" +
"\r\n",

WantProxy: "POST / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Content-Length: 0\r\n" +
"\r\n",
},
@@ -258,13 +259,13 @@

WantWrite: "POST / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Transfer-Encoding: chunked\r\n\r\n" +
chunk("x") + chunk(""),

WantProxy: "POST / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Transfer-Encoding: chunked\r\n\r\n" +
chunk("x") + chunk(""),
},
@@ -365,7 +366,7 @@

WantWrite: "GET /foo HTTP/1.1\r\n" +
"Host: \r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"X-Foo: X-Bar\r\n\r\n",
},

@@ -391,7 +392,7 @@

WantWrite: "GET /search HTTP/1.1\r\n" +
"Host: \r\n" +
- "User-Agent: Go 1.1 package http\r\n\r\n",
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n\r\n",
},

// Opaque test #1 from golang.org/issue/4860
@@ -410,7 +411,7 @@

WantWrite: "GET /%2F/%2F/ HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n\r\n",
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n\r\n",
},

// Opaque test #2 from golang.org/issue/4860
@@ -429,7 +430,7 @@

WantWrite: "GET http://y.google.com/%2F/%2F/ HTTP/1.1\r\n" +
"Host: x.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n\r\n",
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n\r\n",
},

// Testing custom case in header keys. Issue 5022.
@@ -451,7 +452,7 @@

WantWrite: "GET / HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"ALL-CAPS: x\r\n" +
"\r\n",
},
@@ -467,7 +468,7 @@

WantWrite: "GET / HTTP/1.1\r\n" +
"Host: [fe80::1]\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"\r\n",
},

@@ -483,7 +484,7 @@

WantWrite: "GET / HTTP/1.1\r\n" +
"Host: [fe80::1]:8080\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"\r\n",
},
}
@@ -569,7 +570,7 @@
}
expected := "POST / HTTP/1.1\r\n" +
"Host: foo.com\r\n" +
- "User-Agent: Go 1.1 package http\r\n" +
+ "User-Agent: Go-http-client/" + runtime.Version() + "\r\n" +
"Transfer-Encoding: chunked\r\n\r\n" +
// TODO: currently we don't buffer before chunking, so we get a
// single "m" chunk before the other chunks, as this was the 1-byte

--
https://go-review.googlesource.com/9385

Josh Bleecher Snyder (Gerrit)

unread,
Apr 27, 2015, 12:26:29 PM4/27/15
to Aamir Khan, golang-co...@googlegroups.com
Josh Bleecher Snyder has posted comments on this change.

net/http: change default user agent string

Patch Set 1:

As the comment you deleted says, the user-agent "is not intended to reflect
the actual Go version being used." Using the actual Go version has been
proposed before and rejected. I'd trim this CL down to just making the
user-agent conform.

--
https://go-review.googlesource.com/9385
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-HasComments: No

Aamir Khan (Gerrit)

unread,
Apr 27, 2015, 7:52:03 PM4/27/15
to Brad Fitzpatrick, Josh Bleecher Snyder, golang-co...@googlegroups.com
Aamir Khan has posted comments on this change.

net/http: change default user agent string

Patch Set 1:

> As the comment you deleted says, the user-agent "is not intended to
> reflect the actual Go version being used." Using the actual Go
> version has been proposed before and rejected. I'd trim this CL
> down to just making the user-agent conform.

Can you point me to the relevant CL / discussion when it was proposed and
rejected?

--
https://go-review.googlesource.com/9385
Gerrit-Reviewer: Aamir Khan <syst3...@gmail.com>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>

Josh Bleecher Snyder (Gerrit)

unread,
Apr 27, 2015, 7:57:14 PM4/27/15
to Aamir Khan, Brad Fitzpatrick, golang-co...@googlegroups.com
Josh Bleecher Snyder has posted comments on this change.

net/http: change default user agent string

Patch Set 1:

https://codereview.appspot.com/13638045/

Aamir Khan (Gerrit)

unread,
Apr 27, 2015, 10:04:36 PM4/27/15
to Brad Fitzpatrick, Josh Bleecher Snyder, golang-co...@googlegroups.com
Aamir Khan uploaded a new patch set:
https://go-review.googlesource.com/9385

net/http: change default user agent string

Default user agent in use - "Go 1.1 package http" doesn't conform to RFC
7231.
See http://tools.ietf.org/html/rfc7231#section-5.5.3

Use a valid user-agent string instead, including actual go version being
used.

Fixes #9792

Change-Id: I80249709800dcdbf6f2e97a63fab05656898e6aa
---
M src/net/http/httputil/dump_test.go
M src/net/http/request.go
M src/net/http/requestwrite_test.go
3 files changed, 28 insertions(+), 29 deletions(-)

Aamir Khan (Gerrit)

unread,
Apr 27, 2015, 10:14:03 PM4/27/15
to Brad Fitzpatrick, Josh Bleecher Snyder, golang-co...@googlegroups.com
Aamir Khan uploaded a new patch set:
https://go-review.googlesource.com/9385

net/http: change default user agent string

Default user agent in use - "Go 1.1 package http" doesn't conform to RFC
7231.
See http://tools.ietf.org/html/rfc7231#section-5.5.3

Use a valid user-agent string instead.

Fixes #9792

Change-Id: I80249709800dcdbf6f2e97a63fab05656898e6aa
---
M src/net/http/httputil/dump_test.go
M src/net/http/request.go
M src/net/http/requestwrite_test.go

Aamir Khan (Gerrit)

unread,
Apr 27, 2015, 10:32:42 PM4/27/15
to Brad Fitzpatrick, Josh Bleecher Snyder, golang-co...@googlegroups.com
Aamir Khan has posted comments on this change.

net/http: change default user agent string

Patch Set 3:

I've left "1.1" in user-agent as is, for now. Although I really think we
should include the actual go version being used (patch 1) instead of "1.1".
RFC7231 suggests to include product-version.

--
https://go-review.googlesource.com/9385
Gerrit-Reviewer: Aamir Khan <syst3...@gmail.com>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-HasComments: No

Josh Bleecher Snyder (Gerrit)

unread,
Apr 27, 2015, 10:46:03 PM4/27/15
to Aamir Khan, Brad Fitzpatrick, golang-co...@googlegroups.com
Josh Bleecher Snyder has posted comments on this change.

net/http: change default user agent string

Patch Set 3: Run-TryBot+1

R=bradfitz

Gobot Gobot (Gerrit)

unread,
Apr 27, 2015, 10:46:33 PM4/27/15
to Aamir Khan, Brad Fitzpatrick, Josh Bleecher Snyder, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

net/http: change default user agent string

Patch Set 3:

TryBots beginning. Status page: http://farmer.golang.org/try?commit=f80f1abb

--
https://go-review.googlesource.com/9385
Gerrit-Reviewer: Aamir Khan <syst3...@gmail.com>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>

Gobot Gobot (Gerrit)

unread,
Apr 27, 2015, 11:49:08 PM4/27/15
to Aamir Khan, Brad Fitzpatrick, Josh Bleecher Snyder, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

net/http: change default user agent string

Patch Set 3: TryBot-Result+1

TryBots are happy.

Russ Cox (Gerrit)

unread,
Jun 26, 2015, 1:29:32 PM6/26/15
to Aamir Khan, Brad Fitzpatrick, Josh Bleecher Snyder, Gobot Gobot, Russ Cox, golang-co...@googlegroups.com
Russ Cox has posted comments on this change.

net/http: change default user agent string

Patch Set 4: Code-Review+2

--
https://go-review.googlesource.com/9385
Gerrit-Reviewer: Aamir Khan <syst3...@gmail.com>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-HasComments: No

Russ Cox (Gerrit)

unread,
Jun 26, 2015, 1:29:39 PM6/26/15
to Russ Cox, Aamir Khan, golang-...@googlegroups.com, Brad Fitzpatrick, Josh Bleecher Snyder, Gobot Gobot, golang-co...@googlegroups.com
Russ Cox has submitted this change and it was merged.

net/http: change default user agent string

Default user agent in use - "Go 1.1 package http" doesn't conform to RFC
7231.
See http://tools.ietf.org/html/rfc7231#section-5.5.3

Use a valid user-agent string instead.

Fixes #9792

Change-Id: I80249709800dcdbf6f2e97a63fab05656898e6aa
Reviewed-on: https://go-review.googlesource.com/9385
Reviewed-by: Russ Cox <r...@golang.org>
---
M src/net/http/httputil/dump_test.go
M src/net/http/request.go
M src/net/http/requestwrite_test.go
3 files changed, 28 insertions(+), 29 deletions(-)

Approvals:
Russ Cox: Looks good to me, approved
Reply all
Reply to author
Forward
0 new messages