Skip to content

Commit

Permalink
Handle test failure with test_post(TestNetHTTP_v1_2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jul 10, 2024
1 parent 205bac7 commit ceb35bd
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/net/http/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def initialize(method, path, headers, socket)
hash[key] = value
end if @body && @body.include?('=')
end
rescue EOFError
end

def [](key)
Expand Down Expand Up @@ -150,13 +151,27 @@ def parse_path_and_query(path)
def read_body
content_length = @headers['Content-Length']&.to_i
return unless content_length && content_length > 0
@socket.read(content_length)

body = ""
while body.bytesize < content_length
chunk = @socket.read(content_length - body.bytesize)
break unless chunk
body << chunk
end

body
end

def read_chunked_body
body = ""
while (chunk_size = @socket.gets.strip.to_i(16)) > 0
body << @socket.read(chunk_size)
chunk = ""
while chunk.bytesize < chunk_size
part = @socket.read(chunk_size - chunk.bytesize)
break unless part
chunk << part
end
body << chunk
@socket.read(2) # read \r\n after each chunk
end
body
Expand Down

0 comments on commit ceb35bd

Please sign in to comment.