Commit f8c6514a authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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
parent 7aa60d99
......@@ -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 == "" {
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment