mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
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:
commit
d82008ddcf
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user