diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-03 23:42:26 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-03 23:42:26 +0000 |
commit | 57c1406697134de5e6fe11f19d478472b6ac5323 (patch) | |
tree | 95569e91d6c1b3fa273e41688557fd5604d634f7 /test/net | |
parent | e6ccffd96619ab4c7926eaa96fbc8166024201d4 (diff) |
* lib/net/http.rb (Net::HTTPResponse#read_chunked): ensure to skip the
last newline of chunk. [ruby-core:29229]
* test/net/http/utils.rb: add an option for chunked response test.
* test/net/http/test_http.rb: add tests for chunked response.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27605 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/net')
-rw-r--r-- | test/net/http/test_http.rb | 88 | ||||
-rw-r--r-- | test/net/http/utils.rb | 9 |
2 files changed, 79 insertions, 18 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 271c50e802..167eda933e 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -17,7 +17,9 @@ module TestNetHTTP_version_1_1_methods res = http.head('/') assert_kind_of Net::HTTPResponse, res assert_equal $test_net_http_data_type, res['Content-Type'] - assert_equal $test_net_http_data.size, res['Content-Length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_equal $test_net_http_data.size, res['Content-Length'].to_i + end } end @@ -34,8 +36,10 @@ module TestNetHTTP_version_1_1_methods assert_kind_of Net::HTTPResponse, res assert_kind_of String, res.body assert_kind_of String, body - assert_not_nil res['content-length'] - assert_equal $test_net_http_data.size, res['content-length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + assert_equal $test_net_http_data.size, res['content-length'].to_i + end assert_equal $test_net_http_data_type, res['Content-Type'] assert_equal $test_net_http_data.size, body.size assert_equal $test_net_http_data, body @@ -49,8 +53,10 @@ module TestNetHTTP_version_1_1_methods assert_kind_of Net::HTTPResponse, res # assert_kind_of String, res.body # assert_kind_of String, body - assert_not_nil res['content-length'] - assert_equal $test_net_http_data.size, res['content-length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + assert_equal $test_net_http_data.size, res['content-length'].to_i + end assert_equal $test_net_http_data_type, res['Content-Type'] assert_equal $test_net_http_data.size, buf.size assert_equal $test_net_http_data, buf @@ -64,8 +70,10 @@ module TestNetHTTP_version_1_1_methods assert_kind_of Net::HTTPResponse, res # assert_kind_of String, res.body # assert_kind_of String, body - assert_not_nil res['content-length'] - assert_equal $test_net_http_data.size, res['content-length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + assert_equal $test_net_http_data.size, res['content-length'].to_i + end assert_equal $test_net_http_data_type, res['Content-Type'] assert_equal $test_net_http_data.size, buf.size assert_equal $test_net_http_data, buf @@ -89,7 +97,9 @@ module TestNetHTTP_version_1_1_methods assert_kind_of Net::HTTPResponse, res assert_kind_of String, body assert_kind_of String, res.body - assert_not_nil res['content-length'] + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + end assert_equal $test_net_http_data_type, res['Content-Type'] assert_equal $test_net_http_data.size, res.body.size assert_equal $test_net_http_data, res.body @@ -100,7 +110,9 @@ module TestNetHTTP_version_1_1_methods http.get2('/') {|res| assert_kind_of Net::HTTPResponse, res assert_kind_of Net::HTTPResponse, res.header - assert_not_nil res['content-length'] + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + end assert_equal $test_net_http_data_type, res['Content-Type'] assert_kind_of String, res.body assert_kind_of String, res.entity @@ -178,8 +190,10 @@ module TestNetHTTP_version_1_2_methods http.request(req) {|res| assert_kind_of Net::HTTPResponse, res assert_kind_of String, res.body - assert_not_nil res['content-length'] - assert_equal $test_net_http_data.size, res['content-length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + assert_equal $test_net_http_data.size, res['content-length'].to_i + end assert_equal $test_net_http_data.size, res.body.size assert_equal $test_net_http_data, res.body } @@ -189,8 +203,10 @@ module TestNetHTTP_version_1_2_methods req = Net::HTTP::Get.new('/') http.request(req) {|res| assert_kind_of Net::HTTPResponse, res - assert_not_nil res['content-length'] - assert_equal $test_net_http_data.size, res['content-length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + assert_equal $test_net_http_data.size, res['content-length'].to_i + end f = StringIO.new("".force_encoding("ASCII-8BIT")) res.read_body f assert_equal $test_net_http_data.bytesize, f.string.bytesize @@ -209,8 +225,10 @@ module TestNetHTTP_version_1_2_methods req = Net::HTTP::Head.new('/') http.request(req) {|res| assert_kind_of Net::HTTPResponse, res - assert_not_nil res['content-length'] - assert_equal $test_net_http_data.size, res['content-length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + assert_equal $test_net_http_data.size, res['content-length'].to_i + end assert_nil res.body } end @@ -221,7 +239,9 @@ module TestNetHTTP_version_1_2_methods req['Accept'] = $test_net_http_data_type http.request(req, data) {|res| assert_kind_of Net::HTTPResponse, res - assert_equal data.size, res['content-length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_equal data.size, res['content-length'].to_i + end assert_kind_of String, res.body assert_equal data, res.body } @@ -249,7 +269,9 @@ module TestNetHTTP_version_1_2_methods def _test_send_request__GET(http) res = http.send_request('GET', '/') assert_kind_of Net::HTTPResponse, res - assert_equal $test_net_http_data.size, res['content-length'].to_i + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_equal $test_net_http_data.size, res['content-length'].to_i + end assert_kind_of String, res.body assert_equal $test_net_http_data, res.body end @@ -299,6 +321,38 @@ class TestNetHTTP_v1_2 < Test::Unit::TestCase end end +class TestNetHTTP_v1_2_chunked < Test::Unit::TestCase + CONFIG = { + 'host' => '127.0.0.1', + 'port' => 10081, + 'proxy_host' => nil, + 'proxy_port' => nil, + 'chunked' => true, + } + + include TestNetHTTPUtils + include TestNetHTTP_version_1_1_methods + include TestNetHTTP_version_1_2_methods + + def new + Net::HTTP.version_1_2 + super + end + + def test_chunked_break + i = 0 + assert_nothing_raised("[ruby-core:29229]") { + start {|http| + http.request_get('/') {|res| + res.read_body {|chunk| + break + } + } + } + } + end +end + =begin class TestNetHTTP_proxy < Test::Unit::TestCase CONFIG = { diff --git a/test/net/http/utils.rb b/test/net/http/utils.rb index e685a8ff61..10c88d70d7 100644 --- a/test/net/http/utils.rb +++ b/test/net/http/utils.rb @@ -48,6 +48,7 @@ module TestNetHTTPUtils :ShutdownSocketWithoutClose => true, :ServerType => Thread, } + server_config[:OutputBufferSize] = 4 if config('chunked') if defined?(OpenSSL) and config('ssl_enable') server_config.update({ :SSLEnable => true, @@ -56,7 +57,7 @@ module TestNetHTTPUtils }) end @server = WEBrick::HTTPServer.new(server_config) - @server.mount('/', Servlet) + @server.mount('/', Servlet, config('chunked')) @server.start n_try_max = 5 begin @@ -75,15 +76,21 @@ module TestNetHTTPUtils $test_net_http_data_type = 'application/octet-stream' class Servlet < WEBrick::HTTPServlet::AbstractServlet + def initialize(this, chunked = false) + @chunked = chunked + end + def do_GET(req, res) res['Content-Type'] = $test_net_http_data_type res.body = $test_net_http_data + res.chunked = @chunked end # echo server def do_POST(req, res) res['Content-Type'] = req['Content-Type'] res.body = req.body + res.chunked = @chunked end end |