webrick.httpresponse.stringio.patch

Eric Hodel, 03/23/2013 05:00 PM

Download (2.36 KB)

View differences:

lib/webrick/httpresponse.rb (working copy)
299 299
    # Sends the body on +socket+
300 300

  
301 301
    def send_body(socket) # :nodoc:
302
      case @body
303
      when IO then send_body_io(socket)
304
      else send_body_string(socket)
302
      if @body.respond_to? :readpartial then
303
        send_body_io(socket)
304
      else
305
        send_body_string(socket)
305 306
      end
306 307
    end
307 308

  
test/webrick/test_httpresponse.rb (working copy)
1 1
require "webrick"
2 2
require "minitest/autorun"
3
require "stringio"
3 4

  
4 5
module WEBrick
5 6
  class TestHTTPResponse < MiniTest::Unit::TestCase
......
45 46

  
46 47
      assert_equal 0, logger.messages.length
47 48
    end
49

  
50
    def test_send_body_io
51
      body_r, body_w = IO.pipe
52

  
53
      body_w.write 'hello'
54
      body_w.close
55

  
56
      @res.body = body_r
57

  
58
      r, w = IO.pipe
59

  
60
      @res.send_body w
61

  
62
      w.close
63

  
64
      assert_equal 'hello', r.read
65
    end
66

  
67
    def test_send_body_string
68
      @res.body = 'hello'
69

  
70
      r, w = IO.pipe
71

  
72
      @res.send_body w
73

  
74
      w.close
75

  
76
      assert_equal 'hello', r.read
77
    end
78

  
79
    def test_send_body_string_io
80
      @res.body = StringIO.new 'hello'
81

  
82
      r, w = IO.pipe
83

  
84
      @res.send_body w
85

  
86
      w.close
87

  
88
      assert_equal 'hello', r.read
89
    end
90

  
91
    def test_send_body_io_chunked
92
      @res.chunked = true
93

  
94
      body_r, body_w = IO.pipe
95

  
96
      body_w.write 'hello'
97
      body_w.close
98

  
99
      @res.body = body_r
100

  
101
      r, w = IO.pipe
102

  
103
      @res.send_body w
104

  
105
      w.close
106

  
107
      assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
108
    end
109

  
110
    def test_send_body_string_chunked
111
      @res.chunked = true
112

  
113
      @res.body = 'hello'
114

  
115
      r, w = IO.pipe
116

  
117
      @res.send_body w
118

  
119
      w.close
120

  
121
      assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
122
    end
123

  
124
    def test_send_body_string_io_chunked
125
      @res.chunked = true
126

  
127
      @res.body = StringIO.new 'hello'
128

  
129
      r, w = IO.pipe
130

  
131
      @res.send_body w
132

  
133
      w.close
134

  
135
      assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
136
    end
48 137
  end
49 138
end