mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
made body threshold size (the max buffered size after which the response body is buffered to disk) a top-level option
This commit is contained in:
parent
adf3949c07
commit
40a73f5a7b
@ -4,7 +4,8 @@ module HTTPX
|
||||
class Options
|
||||
MAX_CONCURRENT_REQUESTS = 100
|
||||
MAX_RETRIES = 3
|
||||
WINDOW_SIZE = 1 << 14
|
||||
WINDOW_SIZE = 1 << 14 # 16K
|
||||
MAX_BODY_THRESHOLD_SIZE = (1 << 10) * 112 # 112K
|
||||
|
||||
class << self
|
||||
def inherited(klass)
|
||||
@ -48,6 +49,7 @@ module HTTPX
|
||||
:max_concurrent_requests => MAX_CONCURRENT_REQUESTS,
|
||||
:max_retries => MAX_RETRIES,
|
||||
:window_size => WINDOW_SIZE,
|
||||
:body_threshold_size => MAX_BODY_THRESHOLD_SIZE,
|
||||
:request_class => Class.new(Request),
|
||||
:response_class => Class.new(Response),
|
||||
:headers_class => Class.new(Headers),
|
||||
@ -83,6 +85,10 @@ module HTTPX
|
||||
self.window_size = Integer(num)
|
||||
end
|
||||
|
||||
def_option(:body_threshold_size) do |num|
|
||||
self.body_threshold_size = Integer(num)
|
||||
end
|
||||
|
||||
%w[
|
||||
params form json body
|
||||
proxy follow ssl max_retries
|
||||
|
@ -22,7 +22,7 @@ module HTTPX
|
||||
@request = request
|
||||
@status = Integer(status)
|
||||
@headers = @options.headers_class.new(headers)
|
||||
@body = Body.new(self)
|
||||
@body = Body.new(self, threshold_size: @options.body_threshold_size)
|
||||
end
|
||||
|
||||
def <<(data)
|
||||
@ -43,9 +43,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
class Body
|
||||
MAX_THRESHOLD_SIZE = 1024 * (80 + 32) # 112 Kbytes
|
||||
|
||||
def initialize(response, threshold_size: MAX_THRESHOLD_SIZE)
|
||||
def initialize(response, threshold_size: )
|
||||
@response = response
|
||||
@headers = response.headers
|
||||
@threshold_size = threshold_size
|
||||
|
@ -63,6 +63,7 @@ class OptionsSpec < Minitest::Test
|
||||
:body => nil,
|
||||
:follow => nil,
|
||||
:window_size => 16_384,
|
||||
:body_threshold_size => 114_688,
|
||||
:form => {:bar => "bar"},
|
||||
:timeout => Timeout::PerOperation.new,
|
||||
:ssl => {:foo => "bar"},
|
||||
|
@ -23,7 +23,8 @@ class ResponseTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_response_body_to_s
|
||||
body1 = Response::Body.new(Response.new(request, 200, {}))
|
||||
opts = { threshold_size: 1024 }
|
||||
body1 = Response::Body.new(Response.new(request, 200, {}), opts)
|
||||
assert body1.empty?, "body must be empty after initialization"
|
||||
body1 << "foo"
|
||||
assert body1 == "foo", "body must be updated"
|
||||
@ -31,14 +32,15 @@ class ResponseTest < Minitest::Test
|
||||
body1 << "bar"
|
||||
assert body1 == "foobar", "body must buffer subsequent chunks"
|
||||
|
||||
body3 = Response::Body.new(Response.new(request("head"), 200, {}))
|
||||
body3 = Response::Body.new(Response.new(request("head"), 200, {}), opts)
|
||||
assert body3.empty?, "body must be empty after initialization"
|
||||
assert body3 == "", "HEAD requets body must be empty"
|
||||
|
||||
end
|
||||
|
||||
def test_response_body_each
|
||||
body1 = Response::Body.new(Response.new(request, 200, {}))
|
||||
opts = { threshold_size: 1024 }
|
||||
body1 = Response::Body.new(Response.new(request, 200, {}), opts)
|
||||
body1 << "foo"
|
||||
assert body1.each.to_a == %w(foo), "must yield buffer"
|
||||
body1 << "foo"
|
||||
|
Loading…
x
Reference in New Issue
Block a user