mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-06 00:02:08 -04:00
Merge branch 'fixup_decoders_mime_error' into 'master'
Fixup decoders content type checks See merge request honeyryderchuck/httpx!166
This commit is contained in:
commit
24c762a50d
@ -50,7 +50,7 @@ module HTTPX::Transcoder
|
||||
def decode(response)
|
||||
content_type = response.content_type.mime_type
|
||||
|
||||
raise Error, "invalid form mime type (#{content_type})" unless content_type == "application/x-www-form-urlencoded"
|
||||
raise HTTPX::Error, "invalid form mime type (#{content_type})" unless content_type == "application/x-www-form-urlencoded"
|
||||
|
||||
Decoder
|
||||
end
|
||||
|
@ -35,7 +35,7 @@ module HTTPX::Transcoder
|
||||
def decode(response)
|
||||
content_type = response.content_type.mime_type
|
||||
|
||||
raise Error, "invalid json mime type (#{content_type})" unless JSON_REGEX.match?(content_type)
|
||||
raise HTTPX::Error, "invalid json mime type (#{content_type})" unless JSON_REGEX.match?(content_type)
|
||||
|
||||
::JSON.method(:parse)
|
||||
end
|
||||
|
@ -130,10 +130,18 @@ class ResponseTest < Minitest::Test
|
||||
json_response << %({"a": "b"})
|
||||
assert json_response.json == { "a" => "b" }
|
||||
assert json_response.json(symbolize_names: true) == { :a => "b" }
|
||||
json_response << "bogus"
|
||||
assert_raises(JSON::ParserError) { json_response.json }
|
||||
err = assert_raises(HTTPX::Error) { json_response.form }
|
||||
assert err.message == "invalid form mime type (application/json)"
|
||||
|
||||
form_response = Response.new(request, 200, "2.0", { "content-type" => "application/x-www-form-urlencoded" })
|
||||
form_response << "a=b&c=d"
|
||||
assert form_response.form == { "a" => "b", "c" => "d" }
|
||||
err = assert_raises(HTTPX::Error) { form_response.json }
|
||||
assert err.message == "invalid json mime type (application/x-www-form-urlencoded)"
|
||||
form_response << "богус"
|
||||
assert_raises(ArgumentError) { form_response.form }
|
||||
|
||||
form2_response = Response.new(request, 200, "2.0", { "content-type" => "application/x-www-form-urlencoded" })
|
||||
form2_response << "a[]=b&a[]=c&d[e]=f&g[h][i][j]=k&l[m][][n]=o&l[m][][p]=q&l[m][][n]=r&s[=t"
|
||||
|
Loading…
x
Reference in New Issue
Block a user