Skip to content

Commit

Permalink
Add test for request_body. Ensure inets passes.
Browse files Browse the repository at this point in the history
Cowboy is still failing. Request_body is always empty. Why?
  • Loading branch information
choptastic committed Jan 27, 2015
1 parent 836db68 commit d05abec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/sbw.erl
Expand Up @@ -173,9 +173,13 @@ error(Wrapper) ->
?PASSTHROUGH(peer_ip).
?PASSTHROUGH(peer_port).
?PASSTHROUGH(protocol_version).
?PASSTHROUGH(request_body).
?PASSTHROUGH(socket).

request_body(Wrapper) ->
Mod = Wrapper#sbw.mod,
Req = Wrapper#sbw.req,
simple_bridge_util:to_binary(Mod:request_body(Req)).

request_method(Wrapper) ->
Mod = Wrapper#sbw.mod,
Req = Wrapper#sbw.req,
Expand Down
4 changes: 3 additions & 1 deletion src/simple_bridge_util.erl
Expand Up @@ -306,7 +306,9 @@ to_list(B) when is_binary(B) ->
to_list(L) when is_list(L) ->
L.

-spec to_binary(iolist() | atom()) -> binary().
-spec to_binary(iolist() | atom() | binary()) -> binary().
to_binary(B) when is_binary(B) ->
B;
to_binary(A) when is_atom(A) ->
list_to_binary(atom_to_list(A));
to_binary(L) ->
Expand Down
6 changes: 5 additions & 1 deletion test/simple_bridge_SUITE.erl
Expand Up @@ -14,6 +14,7 @@
uri/1,
request_method_get/1,
request_method_post/1,
request_body/1,
query_params/1,
post_params/1
]).
Expand All @@ -23,7 +24,7 @@ all() -> [{group, main}].
groups() ->
[{main,
[parallel, {repeat, 10}],
[peer_ip, request_method_get, request_method_post, protocol, path, query_params, post_params]
[peer_ip, request_method_get, request_method_post, request_body, protocol, path, query_params, post_params]
}].

init_per_group(main, Config) ->
Expand Down Expand Up @@ -55,6 +56,9 @@ request_method_get(_) ->
request_method_post(_) ->
"'POST'" = post("request_method_post", "").

request_body(_) ->
"<<\"my body\">>" = post("request_body", "my body").

query_params(_) ->
"[{<<\"a\">>,<<\"1\">>},{<<\"b\">>,<<\"2\">>}]" = request("query_params?a=1&b=2").

Expand Down
1 change: 1 addition & 0 deletions test/simple_bridge_test_handler.erl
Expand Up @@ -14,6 +14,7 @@ run("/path", Bridge) -> simple_call(path, Bridge);
run("/uri", Bridge) -> simple_call(uri, Bridge);
run("/request_method_get", Bridge) -> simple_call(request_method, Bridge);
run("/request_method_post", Bridge) -> simple_call(request_method, Bridge);
run("/request_body", Bridge) -> simple_call(request_body, Bridge);
run("/query_params", Bridge) -> simple_call(query_params, Bridge);
run("/post_params", Bridge) -> simple_call(post_params, Bridge);
run(Path, _Bridge) -> io_lib:format("Unhandled Path: ~p", [Path]).
Expand Down

0 comments on commit d05abec

Please sign in to comment.