]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: don't modify Request Method's case
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 30 Jul 2012 00:05:24 +0000 (10:05 +1000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 30 Jul 2012 00:05:24 +0000 (10:05 +1000)
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

src/pkg/net/http/response.go
src/pkg/net/http/serve_test.go

index 945ecd8a4b04dbb755ac3f9909041521488d28f0..92d2f499839946b63a4d728aedbd7ec9d7651f4a 100644 (file)
@@ -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 == "" {
index 77ab2eb334998c770c3618b2d6c418095d0b821d..e79e0b604bf0050264e4397cd1ee3d661ebe9784 100644 (file)
@@ -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)