mirror of
https://github.com/edgurgel/httparrot
synced 2025-04-05 16:22:32 -04:00
Return JSON representation of query string parameters in the body of /response-headers
This commit is contained in:
parent
5bf6df34e4
commit
b45b1f146d
2 changed files with 9 additions and 2 deletions
|
@ -21,6 +21,10 @@ defmodule HTTParrot.ResponseHeadersHandler do
|
||||||
req = Enum.reduce qs_vals, req, fn({key, value}, req) ->
|
req = Enum.reduce qs_vals, req, fn({key, value}, req) ->
|
||||||
:cowboy_req.set_resp_header(key, value, req)
|
:cowboy_req.set_resp_header(key, value, req)
|
||||||
end
|
end
|
||||||
{"", req, qs_vals}
|
{response(qs_vals), req, qs_vals}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp response(qs_vals) do
|
||||||
|
qs_vals |> JSX.encode!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ defmodule HTTParrot.ResponseHeadersHandlerTest do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
new :cowboy_req
|
new :cowboy_req
|
||||||
|
new JSX
|
||||||
on_exit fn -> unload end
|
on_exit fn -> unload end
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
@ -28,9 +29,11 @@ defmodule HTTParrot.ResponseHeadersHandlerTest do
|
||||||
test "query string parameters are sent as headers" do
|
test "query string parameters are sent as headers" do
|
||||||
expect(:cowboy_req, :set_resp_header, [{[:k1, :v1, :req1], :req2},
|
expect(:cowboy_req, :set_resp_header, [{[:k1, :v1, :req1], :req2},
|
||||||
{[:k2, :v2, :req2], :req3}])
|
{[:k2, :v2, :req2], :req3}])
|
||||||
|
expect(JSX, :encode!, [{[[k1: :v1, k2: :v2]], :json}])
|
||||||
|
|
||||||
assert get_json(:req1, [k1: :v1, k2: :v2]) == {"", :req3, [k1: :v1, k2: :v2]}
|
assert get_json(:req1, [k1: :v1, k2: :v2]) == {:json, :req3, [k1: :v1, k2: :v2]}
|
||||||
|
|
||||||
assert validate :cowboy_req
|
assert validate :cowboy_req
|
||||||
|
assert validate JSX
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue