From: Brad Fitzpatrick Date: Mon, 30 Jul 2012 00:05:24 +0000 (+1000) Subject: net/http: don't modify Request Method's case X-Git-Tag: go1.1rc2~2756 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f8c6514a1cb11034e96588ddfafdbbba5b0cf27b;p=gostls13.git net/http: don't modify Request Method's case This fixes a data race (usually just harmlessly updating "GET" to "GET"), but also follows RFC 2616 Sec 5.1.1 which says that the request method is case-sensitive. Fixes #3881 R=golang-dev, rsc, dsymonds CC=golang-dev https://golang.org/cl/6446063 --- diff --git a/src/pkg/net/http/response.go b/src/pkg/net/http/response.go index 945ecd8a4b..92d2f49983 100644 --- a/src/pkg/net/http/response.go +++ b/src/pkg/net/http/response.go @@ -107,7 +107,6 @@ func ReadResponse(r *bufio.Reader, req *Request) (resp *Response, err error) { resp = new(Response) resp.Request = req - resp.Request.Method = strings.ToUpper(resp.Request.Method) // Parse the first line of the response. line, err := tp.ReadLine() @@ -188,11 +187,6 @@ func (r *Response) ProtoAtLeast(major, minor int) bool { // func (r *Response) Write(w io.Writer) error { - // RequestMethod should be upper-case - if r.Request != nil { - r.Request.Method = strings.ToUpper(r.Request.Method) - } - // Status line text := r.Status if text == "" { diff --git a/src/pkg/net/http/serve_test.go b/src/pkg/net/http/serve_test.go index 77ab2eb334..e79e0b604b 100644 --- a/src/pkg/net/http/serve_test.go +++ b/src/pkg/net/http/serve_test.go @@ -1188,6 +1188,22 @@ func TestServerGracefulClose(t *testing.T) { <-writeErr } +func TestCaseSensitiveMethod(t *testing.T) { + ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { + if r.Method != "get" { + t.Errorf(`Got method %q; want "get"`, r.Method) + } + })) + defer ts.Close() + req, _ := NewRequest("get", ts.URL, nil) + res, err := DefaultClient.Do(req) + if err != nil { + t.Error(err) + return + } + res.Body.Close() +} + // goTimeout runs f, failing t if f takes more than ns to complete. func goTimeout(t *testing.T, d time.Duration, f func()) { ch := make(chan bool, 2)