diff options
author | Hiroshi SHIBATA <[email protected]> | 2024-07-10 17:00:17 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-07-10 23:06:08 +0000 |
commit | 4e6463ad7a56d7cf55726ff913129790b942ffb9 (patch) | |
tree | d05c6c3c347fd40746cb3ebed2df4e8fdf1f4c30 /test | |
parent | 87a45af1050c07bccf09cb03eb1ce420b62baede (diff) |
[ruby/net-http] Support chunked data and fixed test failure with multipart/form-data
https://github.com/ruby/net-http/commit/b38c2795a9
Diffstat (limited to 'test')
-rw-r--r-- | test/net/http/test_http.rb | 2 | ||||
-rw-r--r-- | test/net/http/utils.rb | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index f369c64ea1..868c5ac558 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -843,6 +843,7 @@ Content-Type: application/octet-stream __EOM__ start {|http| _test_set_form_urlencoded(http, data.reject{|k,v|!v.is_a?(String)}) + @server.mount('/', lambda {|req, res| res.body = req.body }) _test_set_form_multipart(http, false, data, expected) _test_set_form_multipart(http, true, data, expected) } @@ -887,6 +888,7 @@ __EOM__ expected.sub!(/<filename>/, filename) expected.sub!(/<data>/, $test_net_http_data) start {|http| + @server.mount('/', lambda {|req, res| res.body = req.body }) data.each{|k,v|v.rewind rescue nil} req = Net::HTTP::Post.new('/') req.set_form(data, 'multipart/form-data') diff --git a/test/net/http/utils.rb b/test/net/http/utils.rb index 4ea2be1d07..b83664991b 100644 --- a/test/net/http/utils.rb +++ b/test/net/http/utils.rb @@ -96,8 +96,12 @@ module TestNetHTTPUtils @path, @query = parse_path_and_query(path) @headers = headers @socket = socket - if method == 'POST' && @path == '/continue' - @body = read_body + if method == 'POST' && (@path == '/continue' || @headers['Content-Type'].include?('multipart/form-data')) + if @headers['Transfer-Encoding'] == 'chunked' + @body = read_chunked_body + else + @body = read_body + end @query = @body.split('&').each_with_object({}) do |pair, hash| key, value = pair.split('=') hash[key] = value @@ -148,6 +152,15 @@ module TestNetHTTPUtils return unless content_length && content_length > 0 @socket.read(content_length) end + + def read_chunked_body + body = "" + while (chunk_size = @socket.gets.strip.to_i(16)) > 0 + body << @socket.read(chunk_size) + @socket.read(2) # read \r\n after each chunk + end + body + end end class Response |