Compare commits
1
Commits
v1.0.0-rc1
...
1e70698cfc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e70698cfc |
@@ -151,6 +151,41 @@ func wantRequestFields(t *testing.T, line logLine, host string, sent, received i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddsNoContentTypeTheAppDidNotSend(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
const typed = "text/plain"
|
||||||
|
|
||||||
|
app := startApp(t, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.URL.Path == "/typed" {
|
||||||
|
w.Header().Set("Content-Type", typed)
|
||||||
|
} else {
|
||||||
|
// The key with no value keeps Go's server from adding one.
|
||||||
|
w.Header()["Content-Type"] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = io.WriteString(w, "<!doctype html><title>page</title>")
|
||||||
|
})
|
||||||
|
addr, _ := startProxy(t, app.URL, nil)
|
||||||
|
|
||||||
|
// Go's server guesses a Content-Type for an answer without one only
|
||||||
|
// when the first part of the body goes out with the headers, which
|
||||||
|
// happens to some answers and not others: the test asks many times.
|
||||||
|
for range 50 {
|
||||||
|
got := get(t, addr, "/")
|
||||||
|
if got.header.Values("Content-Type") != nil {
|
||||||
|
t.Fatalf("client got Content-Type %q, want none",
|
||||||
|
got.header.Get("Content-Type"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
got := get(t, addr, "/typed")
|
||||||
|
if got.header.Get("Content-Type") != typed {
|
||||||
|
t.Errorf("client got Content-Type %q, want %q",
|
||||||
|
got.header.Get("Content-Type"), typed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestStreamsTheRequestBody(t *testing.T) {
|
func TestStreamsTheRequestBody(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -421,6 +421,13 @@ func (rq *request) modifyResponse(res *http.Response) error {
|
|||||||
return errResponseTooLarge
|
return errResponseTooLarge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Go's server adds a Content-Type it guesses from the body to a
|
||||||
|
// response whose headers have no Content-Type key. The key with no
|
||||||
|
// value sends none, as the app sent none.
|
||||||
|
if res.Header.Get("Content-Type") == "" {
|
||||||
|
rq.out.Header()["Content-Type"] = nil
|
||||||
|
}
|
||||||
|
|
||||||
res.Body = &responseBody{body: limitBody(res.Body, maxBytes), rq: rq}
|
res.Body = &responseBody{body: limitBody(res.Body, maxBytes), rq: rq}
|
||||||
rq.startClientResponseTimeout()
|
rq.startClientResponseTimeout()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user