mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-05 00:02:38 -04:00
allow headers to be pattern-matched as well
This commit is contained in:
parent
c7704b6e15
commit
6229e23765
@ -3,11 +3,11 @@
|
||||
module HTTPX
|
||||
module ResponsePatternMatchExtensions
|
||||
def deconstruct
|
||||
[@status, @headers.to_h, @body]
|
||||
[@status, @headers, @body]
|
||||
end
|
||||
|
||||
def deconstruct_keys(_keys)
|
||||
{ status: @status, headers: @headers.to_h, body: @body }
|
||||
{ status: @status, headers: @headers, body: @body }
|
||||
end
|
||||
end
|
||||
|
||||
@ -21,6 +21,13 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
|
||||
module HeadersPatternMatchExtensions
|
||||
def deconstruct
|
||||
to_a
|
||||
end
|
||||
end
|
||||
|
||||
Headers.include HeadersPatternMatchExtensions
|
||||
Response.include ResponsePatternMatchExtensions
|
||||
ErrorResponse.include ErrorResponsePatternMatchExtensions
|
||||
end
|
||||
|
@ -3,6 +3,16 @@
|
||||
module ResponsePatternMatchTests
|
||||
include HTTPX
|
||||
|
||||
def test_response_headers_deconstruct
|
||||
response = Response.new(request, 200, "2.0", { "host" => "google.com", "content-type" => "application/json" })
|
||||
case response
|
||||
in [_, [*, ["content-type", content_type], *], _]
|
||||
assert content_type == "application/json"
|
||||
else
|
||||
raise "unexpected response"
|
||||
end
|
||||
end
|
||||
|
||||
def test_response_deconstruct
|
||||
response_with_body = Response.new(request, 200, "2.0", { "x-with-body" => "true" })
|
||||
response_with_body << "OK"
|
||||
|
Loading…
x
Reference in New Issue
Block a user