Project

General

Profile

Actions

Bug #9986

closed

WEBrick content-length being set when transfer-encoding is chunked

Added by lengarvey (Leonard Garvey) almost 10 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
trunk, ruby 2.1.2p95
[ruby-core:63372]

Description

It's possible to get WEBrick to return both Transfer-Encoding: chunked and a calculated Content-length header. If the Transfer-encoding header is set via WEBrick::HTTPResponse#[]= then #chunked? will return false and the content length will be set during the setup_headers method. This causes issues with rack and safari (example code for rack can be seen https://github.com/rack/rack/issues/618#issuecomment-47355492). As far as I'm aware WEBrick shouldn't return a content-length when a transfer-encoding chunked header is present. Messages MUST NOT include both a Content-Length header field and a transfer-coding. as per http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html

The following test can be placed into test_httpresponse.rb to demonstrate the issue:

    def test_200_chunked_does_not_set_content_length
      res.body        = 'hello'
      res.status      = 200
      res.chunked     = false
      res["Transfer-Encoding"] = 'chunked'
      res.setup_header

      assert_nil res.header.fetch('content-length', nil)
    end

I've added a patchfile which includes the above test and a fix for the issue.


Files

webrick_transfer_encoding_chunked_content_length.patch (1.07 KB) webrick_transfer_encoding_chunked_content_length.patch lengarvey (Leonard Garvey), 06/27/2014 04:30 PM
webrick_transfer_encoding_chunked_content_length_failing_test.patch (652 Bytes) webrick_transfer_encoding_chunked_content_length_failing_test.patch Failing test for issue 9986 lengarvey (Leonard Garvey), 07/01/2014 01:27 PM
webrick_transfer_encoding_chunked_content_length_fix.patch (423 Bytes) webrick_transfer_encoding_chunked_content_length_fix.patch Fix in HTTPResponse#[]= for issue 9986 lengarvey (Leonard Garvey), 07/01/2014 01:27 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0