Commit 0add1c3e authored by Evan Shaw's avatar Evan Shaw Committed by Brad Fitzpatrick

http/cgi: correctly set request Content-Type

R=bradfitz
CC=golang-dev
https://golang.org/cl/4433087
parent da9b8b83
...@@ -84,6 +84,10 @@ func RequestFromMap(params map[string]string) (*http.Request, os.Error) { ...@@ -84,6 +84,10 @@ func RequestFromMap(params map[string]string) (*http.Request, os.Error) {
r.ContentLength = clen r.ContentLength = clen
} }
if ct := params["CONTENT_TYPE"]; ct != "" {
r.Header.Set("Content-Type", ct)
}
// Copy "HTTP_FOO_BAR" variables to "Foo-Bar" Headers // Copy "HTTP_FOO_BAR" variables to "Foo-Bar" Headers
for k, v := range params { for k, v := range params {
if !strings.HasPrefix(k, "HTTP_") || skipHeader[k] { if !strings.HasPrefix(k, "HTTP_") || skipHeader[k] {
......
...@@ -20,6 +20,7 @@ func TestRequest(t *testing.T) { ...@@ -20,6 +20,7 @@ func TestRequest(t *testing.T) {
"HTTP_FOO_BAR": "baz", "HTTP_FOO_BAR": "baz",
"REQUEST_URI": "/path?a=b", "REQUEST_URI": "/path?a=b",
"CONTENT_LENGTH": "123", "CONTENT_LENGTH": "123",
"CONTENT_TYPE": "text/xml",
"HTTPS": "1", "HTTPS": "1",
"REMOTE_ADDR": "5.6.7.8", "REMOTE_ADDR": "5.6.7.8",
} }
...@@ -37,6 +38,9 @@ func TestRequest(t *testing.T) { ...@@ -37,6 +38,9 @@ func TestRequest(t *testing.T) {
// Tests that we don't put recognized headers in the map // Tests that we don't put recognized headers in the map
t.Errorf("expected User-Agent %q; got %q", e, g) t.Errorf("expected User-Agent %q; got %q", e, g)
} }
if g, e := req.Header.Get("Content-Type"), "text/xml"; e != g {
t.Errorf("expected Content-Type %q; got %q", e, g)
}
if g, e := req.ContentLength, int64(123); e != g { if g, e := req.ContentLength, int64(123); e != g {
t.Errorf("expected ContentLength %d; got %d", e, g) t.Errorf("expected ContentLength %d; got %d", e, g)
} }
......
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