mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-12-06 00:00:28 -05:00
fix for webmock request body expecting a string
when building the request signature, the body is preemptively converted to a string, which fulfills the expectation for webmock, despite it being a bit of a perf penalty if the request contains a multipart request body, as the body will be fully read to memory Closes #319 Closes https://github.com/HoneyryderChuck/httpx/issues/65
This commit is contained in:
parent
492097d551
commit
3e504fb511
@ -155,6 +155,12 @@ class WebmockTest < Minitest::Test
|
|||||||
assert_requested(:get, MOCK_URL_HTTP, query: hash_excluding("a" => %w[b c]))
|
assert_requested(:get, MOCK_URL_HTTP, query: hash_excluding("a" => %w[b c]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_verification_that_expected_request_with_hash_as_body
|
||||||
|
stub_request(:post, MOCK_URL_HTTP).with(body: { foo: "bar" })
|
||||||
|
http_request(:post, MOCK_URL_HTTP, form: { foo: "bar" })
|
||||||
|
assert_requested(:post, MOCK_URL_HTTP, body: { foo: "bar" })
|
||||||
|
end
|
||||||
|
|
||||||
def test_verification_that_non_expected_request_didnt_occur
|
def test_verification_that_non_expected_request_didnt_occur
|
||||||
expected_message = Regexp.new(
|
expected_message = Regexp.new(
|
||||||
"The request GET #{MOCK_URL_HTTP}/ was not expected to execute but it executed 1 time\n\n" \
|
"The request GET #{MOCK_URL_HTTP}/ was not expected to execute but it executed 1 time\n\n" \
|
||||||
|
|||||||
@ -20,7 +20,7 @@ module WebMock
|
|||||||
WebMock::RequestSignature.new(
|
WebMock::RequestSignature.new(
|
||||||
request.verb.downcase.to_sym,
|
request.verb.downcase.to_sym,
|
||||||
uri.to_s,
|
uri.to_s,
|
||||||
body: request.body,
|
body: request.body.to_s,
|
||||||
headers: request.headers.to_h
|
headers: request.headers.to_h
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -18,6 +18,12 @@ module HTTPX
|
|||||||
"multipart/form-data; boundary=#{@boundary}"
|
"multipart/form-data; boundary=#{@boundary}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
read
|
||||||
|
ensure
|
||||||
|
rewind
|
||||||
|
end
|
||||||
|
|
||||||
def read(length = nil, outbuf = nil)
|
def read(length = nil, outbuf = nil)
|
||||||
data = String(outbuf).clear.force_encoding(Encoding::BINARY) if outbuf
|
data = String(outbuf).clear.force_encoding(Encoding::BINARY) if outbuf
|
||||||
data ||= "".b
|
data ||= "".b
|
||||||
|
|||||||
@ -28,6 +28,8 @@ module HTTPX
|
|||||||
|
|
||||||
def content_type: () -> String
|
def content_type: () -> String
|
||||||
|
|
||||||
|
def to_s: () -> String
|
||||||
|
|
||||||
def read: (?int? length, ?string? buffer) -> String?
|
def read: (?int? length, ?string? buffer) -> String?
|
||||||
|
|
||||||
def rewind: () -> void
|
def rewind: () -> void
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user