rails/rails — Issue #3436: head method should not set content-type
Author: whistlerbrk
Created: 2011-10-25 21:02:50+00:00
State: open

From the documentation on guides.rubyonrails.org:

head :created, :location => photo_path(@photo)

Which would produce:

HTTP/1.1 201 Created
Connection: close
Date: Sun, 24 Jan 2010 12:16:44 GMT
Transfer-Encoding: chunked
Location: /photos/1
Content-Type: text/html; charset=utf-8
X-Runtime: 0.083496
Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
Cache-Control: no-cache

Why is Content-Type here set as such?

From RFC2616:

The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.

If we are explicitly using the head method here to only set the headers and blank out the body (In my case I'd like to respond 201 without a body, which is debatably 204) then the intention must be there is no entity-body, and therefore no content type.