Project

General

Profile

Bug #11268 ยป net_http.patch

nkmrya (Yasuhiro Nakamura), 09/08/2015 03:32 PM

View differences:

lib/net/http/generic_request.rb
36 36
        @decode_content = true
37 37
        initheader = initheader ? initheader.dup : {}
38 38
        initheader["accept-encoding"] =
39
          "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
39
          "gzip;q=1.0,identity;q=0.3"
40 40
      end
41 41
    end
42 42

  
......
329 329
  end
330 330

  
331 331
end
332

  
lib/net/http/response.rb
252 252

  
253 253
    v = self['content-encoding']
254 254
    case v && v.downcase
255
    when 'deflate', 'gzip', 'x-gzip' then
255
    when 'gzip', 'x-gzip' then
256 256
      self.delete 'content-encoding'
257 257

  
258 258
      inflate_body_io = Inflater.new(@socket)
......
412 412
  end
413 413

  
414 414
end
415

  
test/net/http/test_http_request.rb
16 16
      'user-agent' => %w[Ruby],
17 17
    }
18 18

  
19
    expected['accept-encoding'] = %w[gzip;q=1.0,deflate;q=0.6,identity;q=0.3] if
19
    expected['accept-encoding'] = %w[gzip;q=1.0,identity;q=0.3] if
20 20
      Net::HTTP::HAVE_ZLIB
21 21

  
22 22
    assert_equal expected, req.to_hash
......
76 76
  end if Net::HTTP::HAVE_ZLIB
77 77

  
78 78
end
79

  
test/net/http/test_httpresponse.rb
75 75
    assert_equal 'hello', body
76 76
  end
77 77

  
78
  def test_read_body_content_encoding_deflate
78
  def test_read_body_content_encoding_gzip
79 79
    io = dummy_io(<<EOS)
80 80
HTTP/1.1 200 OK
81 81
Connection: close
82
Content-Encoding: deflate
83
Content-Length: 13
82
Content-Encoding: gzip
83
Content-Length: 25
84 84

  
85
x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15
85
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
86 86
EOS
87 87

  
88 88
    res = Net::HTTPResponse.read_new(io)
......
98 98
      assert_equal nil, res['content-encoding']
99 99
      assert_equal 'hello', body
100 100
    else
101
      assert_equal 'deflate', res['content-encoding']
102
      assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body
101
      assert_equal 'gzib', res['content-encoding']
102
      assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
103 103
    end
104 104
  end
105 105

  
106
  def test_read_body_content_encoding_deflate_uppercase
106
  def test_read_body_content_encoding_gzip_uppercase
107 107
    io = dummy_io(<<EOS)
108 108
HTTP/1.1 200 OK
109 109
Connection: close
110
Content-Encoding: DEFLATE
111
Content-Length: 13
110
Content-Encoding: GZIP
111
Content-Length: 25
112 112

  
113
x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15
113
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
114 114
EOS
115 115

  
116 116
    res = Net::HTTPResponse.read_new(io)
......
126 126
      assert_equal nil, res['content-encoding']
127 127
      assert_equal 'hello', body
128 128
    else
129
      assert_equal 'DEFLATE', res['content-encoding']
130
      assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body
129
      assert_equal 'GZIP', res['content-encoding']
130
      assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
131 131
    end
132 132
  end
133 133

  
134
  def test_read_body_content_encoding_deflate_chunked
134
  def test_read_body_content_encoding_gzip_chunked
135 135
    io = dummy_io(<<EOS)
136 136
HTTP/1.1 200 OK
137 137
Connection: close
138
Content-Encoding: deflate
138
Content-Encoding: gzip
139 139
Transfer-Encoding: chunked
140 140

  
141
6
142
x\x9C\xCBH\xCD\xC9
143
7
144
\xC9\a\x00\x06,\x02\x15
141
d
142
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD
143
c
144
\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
145 145
0
146 146

  
147 147
EOS
......
159 159
      assert_equal nil, res['content-encoding']
160 160
      assert_equal 'hello', body
161 161
    else
162
      assert_equal 'deflate', res['content-encoding']
163
      assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body
162
      assert_equal 'gzip', res['content-encoding']
163
      assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
164 164
    end
165 165
  end
166 166

  
167
  def test_read_body_content_encoding_deflate_disabled
167
  def test_read_body_content_encoding_gzip_disabled
168 168
    io = dummy_io(<<EOS)
169 169
HTTP/1.1 200 OK
170 170
Connection: close
171
Content-Encoding: deflate
172
Content-Length: 13
171
Content-Encoding: gzip
172
Content-Length: 25
173 173

  
174
x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15
174
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
175 175
EOS
176 176

  
177 177
    res = Net::HTTPResponse.read_new(io)
......
183 183
      body = res.read_body
184 184
    end
185 185

  
186
    assert_equal 'deflate', res['content-encoding'], 'Bug #7831'
187
    assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body, 'Bug #7381'
186
    assert_equal 'gzip', res['content-encoding']
187
    assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
188 188
  end
189 189

  
190
  def test_read_body_content_encoding_deflate_no_length
190
  def test_read_body_content_encoding_gzip_no_length
191 191
    io = dummy_io(<<EOS)
192 192
HTTP/1.1 200 OK
193 193
Connection: close
194
Content-Encoding: deflate
194
Content-Encoding: gzip
195 195

  
196
x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15
196
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
197 197
EOS
198 198

  
199 199
    res = Net::HTTPResponse.read_new(io)
......
209 209
      assert_equal nil, res['content-encoding']
210 210
      assert_equal 'hello', body
211 211
    else
212
      assert_equal 'deflate', res['content-encoding']
213
      assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15\r\n", body
212
      assert_equal 'gzip', res['content-encoding']
213
      assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
214 214
    end
215 215
  end
216 216