diff --git a/ChangeLog b/ChangeLog index 3244299b93..c6c5584522 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Sat Oct 31 17:19:28 2009 NAKAMURA, Hiroshi + + * lib/net/http.rb (Net::HTTPResponse#each_response_header): + cosmetic: '?\ ' -> '?\s' + +Fri Oct 30 22:09:47 2009 NAKAMURA, Hiroshi + + * lib/net/http.rb (Net::HTTPResponse#each_response_header): + accept multiline message header of HTTP response. see #1796. + cf. RFC 2616 '4.2 Message Header'. + + * test/net/http/test_httpresponse.rb: added. + Thu Oct 29 04:41:44 2009 NARUSE, Yui * ruby.c (process_options): call rb_filesystem_encoding(). diff --git a/lib/net/http.rb b/lib/net/http.rb index efc47c0009..d5395767e8 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -2146,13 +2146,20 @@ module Net #:nodoc: end def each_response_header(sock) + key = value = nil while true line = sock.readuntil("\n", true).sub(/\s+\z/, '') break if line.empty? - m = /\A([^:]+):\s*/.match(line) or - raise HTTPBadResponse, 'wrong header line format' - yield m[1], m.post_match + if line[0] == ?\s or line[0] == ?\t and value + value << ' ' unless value.empty? + value << line.strip + else + yield key, value if key + key, value = line.strip.split(/\s*:\s*/, 2) + raise HTTPBadResponse, 'wrong header line format' if value.nil? + end end + yield key, value if key end end diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb new file mode 100644 index 0000000000..ab6fdd0ea9 --- /dev/null +++ b/test/net/http/test_httpresponse.rb @@ -0,0 +1,40 @@ +require 'net/http' +require 'test/unit' +require 'stringio' + +class HTTPResponseTest < Test::Unit::TestCase + def test_singleline_header + io = dummy_io(<