8000 merges r25579 and r25581 from trunk into ruby_1_9_1. · documenting-ruby/ruby@0777c72 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0777c72

Browse files
committed
merges r25579 and r25581 from trunk into ruby_1_9_1.
-- * lib/net/http.rb (Net::HTTPResponse#each_response_header): accept multiline message header of HTTP response. see ruby#1796. cf. RFC 2616 '4.2 Message Header'. * test/net/http/test_httpresponse.rb: added. -- * lib/net/http.rb (Net::HTTPResponse#each_response_header): cosmetic: '?\ ' -> '?\s' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@26511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent a2339bc commit 0777c72

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Sat Oct 31 17:19:28 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
2+
3+
* lib/net/http.rb (Net::HTTPResponse#each_response_header):
4+
cosmetic: '?\ ' -> '?\s'
5+
6+
Fri Oct 30 22:09:47 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
7+
8+
* lib/net/http.rb (Net::HTTPResponse#each_response_header):
9+
accept multiline message header of HTTP response. see #1796.
10+
cf. RFC 2616 '4.2 Message Header'.
11+
12+
* test/net/http/test_httpresponse.rb: added.
13+
114
Thu Oct 29 04:41:44 2009 NARUSE, Yui <naruse@ruby-lang.org>
215

316
* ruby.c (process_options): call rb_filesystem_encoding().

lib/net/http.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,13 +2146,20 @@ def response_class(code)
21462146
end
21472147

21482148
def each_response_header(sock)
2149+
key = value = nil
21492150
while true
21502151
line = sock.readuntil("\n", true).sub(/\s+\z/, '')
21512152
break if line.empty?
2152-
m = /\A([^:]+):\s*/.match(line) or
2153-
raise HTTPBadResponse, 'wrong header line format'
2154-
yield m[1], m.post_match
2153+
if line[0] == ?\s or line[0] == ?\t and value
2154+
value << ' ' unless value.empty?
2155+
value << line.strip
2156+
else
2157+
yield key, value if key
2158+
key, value = line.strip.split(/\s*:\s*/, 2)
2159+
raise HTTPBadResponse, 'wrong header line format' if value.nil?
2160+
end
21552161
end
2162+
yield key, value if key
21562163
end
21572164
end
21582165

test/net/http/test_httpresponse.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'net/http'
2+
require 'test/unit'
3+
require 'stringio'
4+
5+
class HTTPResponseTest < Test::Unit::TestCase
6+
def test_singleline_header
7+
io = dummy_io(<<EOS.gsub(/\n/, "\r\n"))
8+
HTTP/1.1 200 OK
9+
Content-Length: 5
10+
Connection: close
11+
12+
hello
13+
EOS
14+
res = Net::HTTPResponse.read_new(io)
15+
assert_equal('5', res.header['content-length'])
16+
assert_equal('close', res.header['connection'])
17+
end
18+
19+
def test_multiline_header
20+
io = dummy_io(<<EOS.gsub(/\n/, "\r\n"))
21+
HTTP/1.1 200 OK
22+
X-Foo: XXX
23+
YYY
24+
X-Bar:
25+
XXX
26+
\tYYY
27+
28+
hello
29+
EOS
30+
res = Net::HTTPResponse.read_new(io)
31+
assert_equal('XXX YYY', res.header['x-foo'])
32+
assert_equal('XXX YYY', res.header['x-bar'])
33+
end
34+
35+
private
36+
37+
def dummy_io(str)
38+
Net::BufferedIO.new(StringIO.new(str))
39+
end
40+
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define RUBY_VERSION "1.9.1"
2-
#define RUBY_PATCHLEVEL 416
2+
#define RUBY_PATCHLEVEL 417
33
#define RUBY_VERSION_MAJOR 1
44
#define RUBY_VERSION_MINOR 9
55
#define RUBY_VERSION_TEENY 1

0 commit comments

Comments
 (0)
0