Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Add support for JSON responses in web test. #101

merged 1 commit into from

2 participants

Fredrik de Vibe Evan Miller
Fredrik de Vibe

Currently, all responses in boss_web_test are expected to be HTML and are sent to an HTML parser (afaics). This fails on receiving JSON data in the body. The patch checks for content-type application/json, and in that case decodes the body as JSON.

Evan Miller

Great idea, thanks!

Evan Miller evanmiller merged commit 00a45e3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 9, 2012
  1. Add support for JSON responses in web test.

    Fredrik de Vibe authored
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/boss/boss_web_test.erl
10 src/boss/boss_web_test.erl
@@ -370,7 +370,7 @@ receive_response(RequesterPid, Assertions, Continuations) ->
{RequesterPid, Uri, {Status, ResponseHeaders, ResponseBody}} ->
ParsedResponseBody = case ResponseBody of
[] -> [];
- Other -> mochiweb_html:parse(Other)
+ Other -> parse(ResponseHeaders, Other)
exit(RequesterPid, kill),
ParsedResponse = {Status, Uri, ResponseHeaders, ParsedResponseBody},
@@ -382,3 +382,11 @@ receive_response(RequesterPid, Assertions, Continuations) ->
error_logger:error_msg("Unexpected message in receive_response: ~p~n", [Other]),
receive_response(RequesterPid, Assertions, Continuations)
+parse([], Body) ->
+ mochiweb_html:parse(Body);
+parse([Head|Tail], Body) ->
+ case Head of
+ {"Content-Type", "application/json"} -> mochijson2:decode(Body);
+ _ -> parse(Tail, Body)
+ end.
Something went wrong with that request. Please try again.