#74 ✓resolved
Dan Kubb (dkubb)

Content-Length should be added when possible

Reported by Dan Kubb (dkubb) | July 18th, 2008 @ 03:39 PM | in Future

Right now, if the Content-Length isn't provided to Thin, it will pass the request through to the client as-is.

In my case Merb does not automatically add the Content-Length when using HAML (although this could affect ERB and other templating systems, I haven't checked).

If the body were a String or an Array, it would be relatively inexpensive to calculate the Content-Length and include it in the response. This would help in situations where the client has requested keep-alive, but the framework doesn't set Content-Length.

In certain cases, the Content-Length should not be automatically added:

  • When the Status code is 1xx, 204 or 304
  • When the Transfer-Encoding header is set to chunked
  • When the body is neither a String or an Array

Also, I'm not entirely sure about this, but perhaps the Rack guys should be asked to include a test in Rack::Lint to ensure the Content-Length is set by the framework unless one of the above conditions is met.

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) July 18th, 2008 @ 03:51 PM

    I just sent a pull request to macournoyer for the following commit on my fork (dkubb/thin):


  • macournoyer

    macournoyer July 19th, 2008 @ 10:13 AM

    • State changed from “new” to “resolved”

    (from [affccc93679a419c8fca2f92fc11e006687bdf15]) Add Content-Length header to response automatically when possible [#74 state:resolved]


  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) July 19th, 2008 @ 11:26 AM

    @macournoyer: As a side note, do you think Rack::Lint should be updated to ensure the framework either sets Content-Length or Transfer-Encoding: chunked on its own? I think perhaps that should be the case, but I wanted to see what you thought.

  • macournoyer

    macournoyer July 19th, 2008 @ 04:23 PM

    Yeah I think that should be the responsibility of the framework to set Content-Length. Since the framework built the response, it knows better how to compute de length.

    So yeah, I agree that Lint should validate that the app sets it.

  • John

    John January 16th, 2024 @ 07:37 AM

    Ludzie starają się, aby Bardzo trudno jest znaleźć renomowane i rzetelne kasyno internetowe. Jeśli spojrzysz na kasyno VulkanBet, będziesz pewien, że jest to coś, co może pomóc ci przestać wykonywać pracę, której nienawidzisz, Nie mogłem uwierzyć, że mogę zarabiać pieniądze z zabawy. Poza tym to niesamowite, że nie muszę pracować cały dzień, żeby mieć wystarczająco dużo https://vulkan-bet.me/ pieniędzy.

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 ยป

People watching this ticket