mirror of https://github.com/golang/go.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
This commit is contained in:
parent
7aa60d998a
commit
f8c6514a1c
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue