Merge branch 'fix-stream-plugin' into 'master'

stream plugin: reverted back to yielding buffered payloads for streamed responses

See merge request os85/httpx!340
This commit is contained in:
HoneyryderChuck 2024-05-14 14:21:09 +00:00
commit d82008ddcf
4 changed files with 22 additions and 4 deletions

View File

@ -48,10 +48,10 @@ module HTTPX
attr_accessor :family
def initialize(uri, options)
@origins = [uri.origin]
@origin = Utils.to_uri(uri.origin)
@options = Options.new(options)
@type = initialize_type(uri, @options)
@origins = [uri.origin]
@origin = Utils.to_uri(uri.origin)
@window_size = @options.window_size
@read_buffer = Buffer.new(@options.buffer_size)
@write_buffer = Buffer.new(@options.buffer_size)

View File

@ -16,9 +16,18 @@ module HTTPX
begin
@on_chunk = block
if @request.response
# if we've already started collecting the payload, yield it first
# before proceeding.
body = @request.response.body
body.each do |chunk|
on_chunk(chunk)
end
end
response.raise_for_status
ensure
response.close if @response
@on_chunk = nil
end
end

View File

@ -108,7 +108,7 @@ class SessionTest < Minitest::Test
response = session.post(uri, body: StringIO.new("a" * 65_536 * 3 * 5))
verify_error_response(response, HTTPX::WriteTimeoutError)
response1 = session.post(uri, body: StringIO.new("a" * 65_536 * 2 * 5))
response1 = session.post(uri, body: StringIO.new("a" * 65_536))
verify_status(response1, 200)
end
end

View File

@ -37,6 +37,15 @@ module Requests
assert payload.lines.size == 3, "all the lines should have been yielded"
end
def test_plugin_stream_each_after_buffer
session = HTTPX.plugin(:stream)
response = session.get(build_uri("/stream/3"), stream: true)
verify_status(response, 200) # forces buffering
payload = response.each.to_a.join
assert payload.lines.size == 3, "all the lines should have been yielded"
end
def test_plugin_stream_each_line
session = HTTPX.plugin(:stream)