#87 ✓hold
Iñaki Baz Castillo

Lint raises if 200 response with no body doesn't contain "Content-Type"

Reported by Iñaki Baz Castillo | December 24th, 2009 @ 01:00 PM

When performing a PUT request my app replies 200 or 201 with "Content-Length: 0" and without body and "Content-Type".

However Lint raises bacause a 200 or 201 response "must contain 'Content-Type'":

STATUS_WITH_NO_ENTITY_BODY = Set.new((100..199).to_a << 204 << 304)
assert("No Content-Type header found") {
  Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i

RFC 2616 states that a message requires "Content-Type" in case it has body:

RFC 2616 - 7.2.1 Type

Any HTTP/1.1 message containing an entity-body SHOULD include a
Content-Type header field defining the media type of that body.

Comments and changes to this ticket

  • Matías Flores

    Matías Flores January 21st, 2010 @ 09:13 PM

    It's a bit confusing, as that same RFC but on a different section (4.3) also states that:

    • All responses to the HEAD request method MUST NOT include a message-body.
    • All 1xx (informational), 204 (no content), and 304 (not modified) responses MUST NOT include a message-body.
    • All other responses do include a message-body, although it MAY be of zero length.

    So, strictly speaking, it seems that in the example you mentioned you do have a message-body but of zero length. And as per section 7.2.1 if you have a body then you SHOULD include the Content-Type header.

    Notice that even if this interpretation happens to be right this would still be a SHOULD, not a MUST, so your point may still be valid. I'm not sure how Rack::Lint is or should be handling unsatisfied SHOULDs.

  • Iñaki Baz Castillo

    Iñaki Baz Castillo January 21st, 2010 @ 09:53 PM

    Yes, the RFC seems a bit confusing. But I think that in cases like this it's better to choose the common sense:

    If I sent a PUT and the response is a 200 with no body (Content-Length: 0) why should the response declare a content type if there si no such content?

  • Graham Batty

    Graham Batty March 2nd, 2010 @ 10:36 PM

    The RFC doesn't seem confusing to me at all. 200 replies always have a content body, and content-length:0 implicitly admits this anyways. If there's a body, it has a type and the type should be sent back.

    It seems like SHOULDs should really probably be warnings, not errors. I don't think Lint is capable of that as it stands, though.

  • Iñaki Baz Castillo

    Iñaki Baz Castillo March 3rd, 2010 @ 12:25 AM

    Content-Lenght:0 is required as in any protocol over a reliable transport protocol (TCP in this case). If not there is no way the http client to know where the response ends and where other message starts. By inspecting the Content-Lenght value the parser know how many bytes it must read after the blank line separator between HTTP headers and body (if it exists).

    IMHO it's clear that a response with no body doesn't require a Content-Type (as there is no content in the body). Not sure where is the possible doubt as RFC 2616 clearly states:

    7.2.1 Type
    Any HTTP/1.1 message containing an entity-body SHOULD include a
    Content-Type header field defining the media type of that body.

    It's clear from the specification that a message without body doens't require to include a Content-Type header.

  • raggi

    raggi May 3rd, 2011 @ 07:44 AM

    • State changed from “new” to “hold”
    • Milestone order changed from “0” to “0”

    nginx disagrees, and ELB agrees. Not concerned. Holding until someone produces a patch

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »