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 1005235
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions test/net/http/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,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 Expand Up @@ -304,7 +318,15 @@ def handle_get(path, headers, socket)
end

def handle_post(path, headers, socket)
body = socket.read(headers['Content-Length'].to_i)
content_length = headers['Content-Length']&.to_i
return unless content_length && content_length > 0

body = ""
while body.bytesize < content_length
chunk = socket.read(content_length - body.bytesize)
break unless chunk
body << chunk
end
scheme = headers['X-Request-Scheme'] || 'http'
host = @config['host']
port = socket.addr[1]
Expand Down

0 comments on commit 1005235

Please sign in to comment.