Skip to content

ServeError should propertly set headers#4

Open
minigolf2000 wants to merge 1 commit into
jixwanwang:masterfrom
minigolf2000:serve_error_bugfix
Open

ServeError should propertly set headers#4
minigolf2000 wants to merge 1 commit into
jixwanwang:masterfrom
minigolf2000:serve_error_bugfix

Conversation

@minigolf2000

Copy link
Copy Markdown

Successful responses are correctly being handled. But currently there's a bug where ServeError returns the response body without actually setting headers. As a result, Content-Length is not set, and Content-Type ends up defaulted to text/plain charset=utf-8.

The reason is because https://golang.org/pkg/net/http/#ResponseWriter

Changing the header map after a call to WriteHeader (or
Write) has no effect unless the modified headers are
trailers.

The correct order of operations, for both success and failure, is:

  1. set headers with w.Header().set()
  2. set response code through w.WriteHeader()
  3. w.Write()

I noticed Vinyl has this bug too lol we should fix that at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants