From b45b1f146db43977b74a499a33c7f82e7c8a3664 Mon Sep 17 00:00:00 2001 From: Luper Rouch Date: Tue, 28 Apr 2015 12:40:28 +0200 Subject: [PATCH] Return JSON representation of query string parameters in the body of /response-headers --- lib/httparrot/response_headers_handler.ex | 6 +++++- test/response_headers_handler_test.exs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/httparrot/response_headers_handler.ex b/lib/httparrot/response_headers_handler.ex index 2752ae8..b638927 100644 --- a/lib/httparrot/response_headers_handler.ex +++ b/lib/httparrot/response_headers_handler.ex @@ -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 diff --git a/test/response_headers_handler_test.exs b/test/response_headers_handler_test.exs index 14c8a96..4d1a527 100644 --- a/test/response_headers_handler_test.exs +++ b/test/response_headers_handler_test.exs @@ -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