ruby-changes:14662
From: yugui <ko1@a...>
Date: Sat, 30 Jan 2010 22:22:38 +0900 (JST)
Subject: [ruby-changes:14662] Ruby:r26511 (ruby_1_9_1): merges r25579 and r25581 from trunk into ruby_1_9_1.
yugui 2010-01-30 21:54:29 +0900 (Sat, 30 Jan 2010) New Revision: 26511 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26511 Log: 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 #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' Added files: branches/ruby_1_9_1/test/net/http/test_httpresponse.rb Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/lib/net/http.rb branches/ruby_1_9_1/version.h Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 26510) +++ ruby_1_9_1/ChangeLog (revision 26511) @@ -1,3 +1,16 @@ +Sat Oct 31 17:19:28 2009 NAKAMURA, Hiroshi <nahi@r...> + + * lib/net/http.rb (Net::HTTPResponse#each_response_header): + cosmetic: '?\ ' -> '?\s' + +Fri Oct 30 22:09:47 2009 NAKAMURA, Hiroshi <nahi@r...> + + * 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 <naruse@r...> * ruby.c (process_options): call rb_filesystem_encoding(). Index: ruby_1_9_1/lib/net/http.rb =================================================================== --- ruby_1_9_1/lib/net/http.rb (revision 26510) +++ ruby_1_9_1/lib/net/http.rb (revision 26511) @@ -2146,13 +2146,20 @@ 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 Index: ruby_1_9_1/version.h =================================================================== --- ruby_1_9_1/version.h (revision 26510) +++ ruby_1_9_1/version.h (revision 26511) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 416 +#define RUBY_PATCHLEVEL 417 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_1/test/net/http/test_httpresponse.rb =================================================================== --- ruby_1_9_1/test/net/http/test_httpresponse.rb (revision 0) +++ ruby_1_9_1/test/net/http/test_httpresponse.rb (revision 26511) @@ -0,0 +1,40 @@ +require 'net/http' +require 'test/unit' +require 'stringio' + +class HTTPResponseTest < Test::Unit::TestCase + def test_singleline_header + io = dummy_io(<<EOS.gsub(/\n/, "\r\n")) +HTTP/1.1 200 OK +Content-Length: 5 +Connection: close + +hello +EOS + res = Net::HTTPResponse.read_new(io) + assert_equal('5', res.header['content-length']) + assert_equal('close', res.header['connection']) + end + + def test_multiline_header + io = dummy_io(<<EOS.gsub(/\n/, "\r\n")) +HTTP/1.1 200 OK +X-Foo: XXX + YYY +X-Bar: + XXX +\tYYY + +hello +EOS + res = Net::HTTPResponse.read_new(io) + assert_equal('XXX YYY', res.header['x-foo']) + assert_equal('XXX YYY', res.header['x-bar']) + end + +private + + def dummy_io(str) + Net::BufferedIO.new(StringIO.new(str)) + end +end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/