Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10974 (new defect)

Opened 7 months ago

Last modified 5 months ago

[PATCH] HEAD request should have no body

Reported by: wzph Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc:

Description

There is a discussion surrounding this issue at 9524. I have two responses to that discussion.

"This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view."

As a HEAD request is a safe request, it seems to be oblique to the intent of the 204. A 200 seems more appropriate and standard.

"The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response."

It seems pretty clear that to be HTTP 1.1 compliant, a HEAD request cannot return a body.

The patch attached ensures that the default status code for a HEAD request is 200, as well as returning no response message body. It also ensures that you can set the status code for a HEAD request to other than 200.

I added a render type (:empty_body). This was an attempt to preclude Safari-specific logic. Instead, render :nothing will continue to send a single space as the body, but a render :empty_body will send nothing. In the patch, head now uses render :empty_body

Also, there were a few tests that were looking for HEAD requests to return a single space in the body. These have been changed to look for an empty body.

Attachments

head_should_return_empty_body.diff (5.1 kB) - added by wzph on 01/31/08 21:04:38.
HEAD should return a 200 by default, and an empty body.

Change History

01/31/08 21:04:38 changed by wzph

  • attachment head_should_return_empty_body.diff added.

HEAD should return a 200 by default, and an empty body.

03/13/08 18:45:03 changed by david

The empty string body was there to work around I believe a Safari bug. I wonder if that has been cured or if anyone else has the details on that.

03/19/08 00:08:03 changed by wzph

Two questions, to which I don't know the answers.

1. Does Safari ever send HEAD requests? If not, this patch shouldn't encounter an error there.

2. Even if Safari does send a HEAD request, does it then render the (empty) body? If not, this patch shouldn't create troubles there either.