mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
testing Response#read
This commit is contained in:
parent
51e1994f56
commit
aebadc8bc9
@ -28,14 +28,12 @@ module HTTPX
|
||||
# number of seconds after which one can retry the request
|
||||
def_option(:retry_after) do |num|
|
||||
# return early if callable
|
||||
if num.respond_to?(:call)
|
||||
num
|
||||
else
|
||||
unless num.respond_to?(:call)
|
||||
num = Integer(num)
|
||||
raise Error, ":retry_after must be positive" unless num.positive?
|
||||
|
||||
num
|
||||
end
|
||||
|
||||
num
|
||||
end
|
||||
|
||||
def_option(:max_retries) do |num|
|
||||
|
@ -103,6 +103,8 @@ module HTTPX
|
||||
def read(*args)
|
||||
return unless @buffer
|
||||
|
||||
rewind
|
||||
|
||||
@buffer.read(*args)
|
||||
end
|
||||
|
||||
|
@ -51,7 +51,7 @@ module HTTPX
|
||||
stream.refuse
|
||||
end
|
||||
|
||||
def fetch_response(request, connections, options)
|
||||
def fetch_response(request, _, _)
|
||||
@responses.delete(request)
|
||||
end
|
||||
|
||||
|
@ -49,6 +49,15 @@ class ResponseTest < Minitest::Test
|
||||
assert body3 == "", "HEAD requets body must be empty"
|
||||
end
|
||||
|
||||
def test_response_body_read
|
||||
body1 = Response::Body.new(Response.new(request, 200, "2.0", {}), threshold_size: 1024)
|
||||
body1.write("foo")
|
||||
assert body1.bytesize == 3
|
||||
assert body1.read(1), "f"
|
||||
assert body1.read(1), "o"
|
||||
assert body1.read(1), "o"
|
||||
end
|
||||
|
||||
def test_response_body_each
|
||||
body1 = Response::Body.new(Response.new(request, 200, "2.0", {}), threshold_size: 1024)
|
||||
body1.write("foo")
|
||||
|
Loading…
x
Reference in New Issue
Block a user