Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http/httptest: ResponseRecorder does not include detected Content-Type header. #9004

Closed
gopherbot opened this issue Oct 27, 2014 · 3 comments

Comments

@gopherbot
Copy link

by alex.tomlins@digital.cabinet-office.gov.uk:

With a real response, the Content-Type header will be set using http.DetectContentType
if it hasn't already been set explicitly.  httptest.ResponseRecorder does not share this
behaviour.

I found this behaviour somewhat confusing - it took me a while to track down why the
ResponseRecorder headers didn't match the headers I was seeing with curl.

What does 'go version' print?

go version go1.3.3 linux/amd64

What steps reproduce the problem?

http://play.golang.org/p/mOjVsUQA-T

What happened?

The ResponseRecorder instance had no Content-Type header set.

What should have happened instead?

It should have been set to the content type detected from the response body.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-none.

@bradfitz
Copy link
Contributor

Comment 2:

Can't really change it now (even if we wanted to) as it would break people's tests.  So
probably just a documentation issue.
But even the net/http ResponseWriter contract doesn't say what the behavior is here, so
I think the httptest.Recorder is more faithful: it records exactly what you did. No
magic recording.
We should document on both sides.
Somewhat related: issue #8992 for omitting the Content-Type from handlers.

Labels changed: added documentation.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

bradfitz commented Feb 5, 2016

Actually, we ended up fixing this in Go 1.6 in git rev 0bf515c for #12986

@bradfitz bradfitz closed this as completed Feb 5, 2016
@golang golang locked and limited conversation to collaborators Feb 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants