The documentation for http.ResponseWriter specifies certain behaviors for the Header() Header and the Write([]byte) (int, error) functions that are not being implemented by httptest.ResponseRecorder currently. Specifically -
- in
Write() If the Header does not contain a Content-Type line, Write adds a Content-Type set to the result of passing the initial 512 bytes of written data to DetectContentType.
- Changing the header after a call to WriteHeader (or Write) has no effect unless the modified headers were declared as trailers by setting the "Trailer" header before the call to WriteHeader
I ran into this issue when looking for Content-Type header from ResponseRecorder and looking at the code for ResponseRecorder, did not see an implementation for the spec.