mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 21:49:06 +02:00
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' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@26511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a2339bc021
commit
0777c729cd
4 changed files with 64 additions and 4 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
Sat Oct 31 17:19:28 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/net/http.rb (Net::HTTPResponse#each_response_header):
|
||||||
|
cosmetic: '?\ ' -> '?\s'
|
||||||
|
|
||||||
|
Fri Oct 30 22:09:47 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Thu Oct 29 04:41:44 2009 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* ruby.c (process_options): call rb_filesystem_encoding().
|
* ruby.c (process_options): call rb_filesystem_encoding().
|
||||||
|
|
|
@ -2146,14 +2146,21 @@ module Net #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_response_header(sock)
|
def each_response_header(sock)
|
||||||
|
key = value = nil
|
||||||
while true
|
while true
|
||||||
line = sock.readuntil("\n", true).sub(/\s+\z/, '')
|
line = sock.readuntil("\n", true).sub(/\s+\z/, '')
|
||||||
break if line.empty?
|
break if line.empty?
|
||||||
m = /\A([^:]+):\s*/.match(line) or
|
if line[0] == ?\s or line[0] == ?\t and value
|
||||||
raise HTTPBadResponse, 'wrong header line format'
|
value << ' ' unless value.empty?
|
||||||
yield m[1], m.post_match
|
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
|
||||||
end
|
end
|
||||||
|
yield key, value if key
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# next is to fix bug in RDoc, where the private inside class << self
|
# next is to fix bug in RDoc, where the private inside class << self
|
||||||
|
|
40
test/net/http/test_httpresponse.rb
Normal file
40
test/net/http/test_httpresponse.rb
Normal file
|
@ -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
|
|
@ -1,5 +1,5 @@
|
||||||
#define RUBY_VERSION "1.9.1"
|
#define RUBY_VERSION "1.9.1"
|
||||||
#define RUBY_PATCHLEVEL 416
|
#define RUBY_PATCHLEVEL 417
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
#define RUBY_VERSION_MINOR 9
|
#define RUBY_VERSION_MINOR 9
|
||||||
#define RUBY_VERSION_TEENY 1
|
#define RUBY_VERSION_TEENY 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue