1
0
Fork 0
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:
Luper Rouch 2015-04-28 12:40:28 +02:00
parent 5bf6df34e4
commit b45b1f146d
2 changed files with 9 additions and 2 deletions

View file

@ -21,6 +21,10 @@ defmodule HTTParrot.ResponseHeadersHandler do
req = Enum.reduce qs_vals, req, fn({key, value}, req) ->
:cowboy_req.set_resp_header(key, value, req)
end
{"", req, qs_vals}
{response(qs_vals), req, qs_vals}
end
defp response(qs_vals) do
qs_vals |> JSX.encode!
end
end

View file

@ -5,6 +5,7 @@ defmodule HTTParrot.ResponseHeadersHandlerTest do
setup do
new :cowboy_req
new JSX
on_exit fn -> unload end
:ok
end
@ -28,9 +29,11 @@ defmodule HTTParrot.ResponseHeadersHandlerTest do
test "query string parameters are sent as headers" do
expect(:cowboy_req, :set_resp_header, [{[:k1, :v1, :req1], :req2},
{[: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 JSX
end
end