mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
added versioning to response (important to test h2c, but also to ensure which 1.x is responding)
This commit is contained in:
parent
518ed5280e
commit
284bb06663
@ -73,7 +73,10 @@ module HTTPX
|
||||
|
||||
log(2) { "headers received" }
|
||||
headers = @options.headers_class.new(h)
|
||||
response = @options.response_class.new(@requests.last, @parser.status_code, headers, @options)
|
||||
response = @options.response_class.new(@requests.last,
|
||||
@parser.status_code,
|
||||
@parser.http_version.join("."),
|
||||
headers, @options)
|
||||
log { "-> HEADLINE: #{response.status} HTTP/#{@parser.http_version.join(".")}" }
|
||||
log { response.headers.each.map { |f, v| "-> HEADER: #{f}: #{v}" }.join("\n") }
|
||||
|
||||
|
@ -59,7 +59,7 @@ module HTTPX
|
||||
end
|
||||
_, status = h.shift
|
||||
headers = @options.headers_class.new(h)
|
||||
response = @options.response_class.new(request, status, headers, @options)
|
||||
response = @options.response_class.new(request, status, "2.0", headers, @options)
|
||||
request.response = response
|
||||
@streams[request] = stream
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ module HTTPX
|
||||
class Response
|
||||
extend Forwardable
|
||||
|
||||
attr_reader :status, :headers, :body
|
||||
attr_reader :status, :headers, :body, :version
|
||||
|
||||
def_delegator :@body, :to_s
|
||||
|
||||
@ -21,8 +21,9 @@ module HTTPX
|
||||
|
||||
def_delegator :@request, :uri
|
||||
|
||||
def initialize(request, status, headers, options = {})
|
||||
@options = Options.new(options)
|
||||
def initialize(request, status, version, headers, options = {})
|
||||
@options = Options.new(options)
|
||||
@version = version
|
||||
@request = request
|
||||
@status = Integer(status)
|
||||
@headers = @options.headers_class.new(headers)
|
||||
|
@ -24,7 +24,7 @@ class ClientTest < Minitest::Test
|
||||
assert request.headers.respond_to?(:foo), "headers methods haven't been added"
|
||||
assert request.headers.foo == "headers-foo", "headers method is unexpected"
|
||||
assert client.respond_to?(:response), "response constructor was added"
|
||||
response = client.response(nil, 200, {})
|
||||
response = client.response(nil, 200, "2.0", {})
|
||||
assert response.respond_to?(:foo), "response methods haven't been added"
|
||||
assert response.foo == "response-foo", "response method is unexpected"
|
||||
assert request.headers.respond_to?(:foo), "headers methods haven't been added"
|
||||
|
@ -6,9 +6,9 @@ class ResponseTest < Minitest::Test
|
||||
include HTTPX
|
||||
|
||||
def test_response_status
|
||||
r1 = Response.new(request, 200, {})
|
||||
r1 = Response.new(request, 200, "1.1", {})
|
||||
assert r1.status == 200, "unexpected status code (#{r1.status})"
|
||||
r2 = Response.new(request, "200", {})
|
||||
r2 = Response.new(request, "200", "1.1", {})
|
||||
assert r2.status == 200, "unexpected status code (#{r2.status})"
|
||||
end
|
||||
|
||||
@ -24,7 +24,7 @@ class ResponseTest < Minitest::Test
|
||||
|
||||
def test_response_body_to_s
|
||||
opts = { threshold_size: 1024 }
|
||||
body1 = Response::Body.new(Response.new(request, 200, {}), opts)
|
||||
body1 = Response::Body.new(Response.new(request, 200, "2.0", {}), opts)
|
||||
assert body1.empty?, "body must be empty after initialization"
|
||||
body1.write("foo")
|
||||
assert body1 == "foo", "body must be updated"
|
||||
@ -32,7 +32,7 @@ class ResponseTest < Minitest::Test
|
||||
body1.write("bar")
|
||||
assert body1 == "foobar", "body must buffer subsequent chunks"
|
||||
|
||||
body3 = Response::Body.new(Response.new(request("head"), 200, {}), opts)
|
||||
body3 = Response::Body.new(Response.new(request("head"), 200, "2.0", {}), opts)
|
||||
assert body3.empty?, "body must be empty after initialization"
|
||||
assert body3 == "", "HEAD requets body must be empty"
|
||||
|
||||
@ -40,7 +40,7 @@ class ResponseTest < Minitest::Test
|
||||
|
||||
def test_response_body_each
|
||||
opts = { threshold_size: 1024 }
|
||||
body1 = Response::Body.new(Response.new(request, 200, {}), opts)
|
||||
body1 = Response::Body.new(Response.new(request, 200, "2.0", {}), opts)
|
||||
body1.write("foo")
|
||||
assert body1.each.to_a == %w(foo), "must yield buffer"
|
||||
body1.write("foo")
|
||||
@ -59,6 +59,6 @@ class ResponseTest < Minitest::Test
|
||||
end
|
||||
|
||||
def resource
|
||||
@resource ||= Response.new(request, 200, {})
|
||||
@resource ||= Response.new(request, 200, "2.0", {})
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user