204_304_keep_alive.patch

Aaron Patterson, 12/10/2011 09:46 AM

Download (1.79 KB)

View differences:

lib/webrick/httpresponse.rb
202 202
      if @header['connection'] == "close"
203 203
         @keep_alive = false
204 204
      elsif keep_alive?
205
        if chunked? || @header['content-length']
205
        if chunked? || @header['content-length'] || @status == 304 || @status == 204
206 206
          @header['connection'] = "Keep-Alive"
207 207
        else
208 208
          msg = "Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true"
test/webrick/test_httpresponse.rb
1
require "webrick"
2
require "minitest/autorun"
3

  
4
module WEBrick
5
  class TestHTTPResponse < MiniTest::Unit::TestCase
6
    class FakeLogger
7
      attr_reader :messages
8

  
9
      def initialize
10
        @messages = []
11
      end
12

  
13
      def warn msg
14
        @messages << msg
15
      end
16
    end
17

  
18
    def test_304_does_not_log_warning
19
      logger          = FakeLogger.new
20
      config          = Config::HTTP
21
      config[:Logger] = logger
22

  
23
      res             = HTTPResponse.new config
24
      res.status      = 304
25
      res.keep_alive  = true
26

  
27
      res.setup_header
28

  
29
      assert_equal 0, logger.messages.length
30
    end
31

  
32
    def test_204_does_not_log_warning
33
      logger          = FakeLogger.new
34
      config          = Config::HTTP
35
      config[:Logger] = logger
36

  
37
      res             = HTTPResponse.new config
38
      res.status      = 204
39
      res.keep_alive  = true
40

  
41
      res.setup_header
42

  
43
      assert_equal 0, logger.messages.length
44
    end
45
  end
46
end