Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cowboy 0.8.0 issue #13

Merged
merged 1 commit into from Mar 18, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/rfc4627_jsonrpc_cowboy.erl
Expand Up @@ -77,21 +77,21 @@ normalize(X) when is_list(X) ->
%% where `handle_non_jsonrpc_request' does the obvious thing for %% where `handle_non_jsonrpc_request' does the obvious thing for
%% non-JSON-RPC requests. %% non-JSON-RPC requests.
handle(AliasPrefix, Req) -> handle(AliasPrefix, Req) ->
{BinaryPath, _} = cowboy_http_req:raw_path(Req), {BinaryPath, _} = cowboy_req:path(Req),
Path = binary_to_list(BinaryPath), Path = binary_to_list(BinaryPath),
{QSVals, _} = cowboy_http_req:qs_vals(Req), {QSVals, _} = cowboy_req:qs_vals(Req),
QueryObj = {obj, [{binary_to_list(K), V} || {K,V} <- QSVals]}, QueryObj = {obj, [{binary_to_list(K), V} || {K,V} <- QSVals]},
{Hdrs, _} = cowboy_http_req:headers(Req), {Hdrs, _} = cowboy_req:headers(Req),
HeaderObj = {obj, [{normalize(K), V} || {K,V} <- Hdrs]}, HeaderObj = {obj, [{normalize(K), V} || {K,V} <- Hdrs]},
{PeerAddr, _} = cowboy_http_req:peer_addr(Req), {PeerAddr, _} = cowboy_req:peer_addr(Req),
Peer = list_to_binary(inet_parse:ntoa(PeerAddr)), Peer = list_to_binary(inet_parse:ntoa(PeerAddr)),
{Method, _} = cowboy_http_req:method(Req), {Method, _} = cowboy_req:method(Req),
RequestInfo = {obj, [{"http_method", list_to_binary(atom_to_list(Method))}, RequestInfo = {obj, [{"http_method", Method},
{"http_query_parameters", QueryObj}, {"http_query_parameters", QueryObj},
{"http_headers", HeaderObj}, {"http_headers", HeaderObj},
{"remote_peername", Peer}, {"remote_peername", Peer},
{"scheme", <<"http">>}]}, {"scheme", <<"http">>}]},
{ok, Body, _} = cowboy_http_req:body(Req), {ok, Body, _} = cowboy_req:body(Req),


case rfc4627_jsonrpc_http:invoke_service_method(AliasPrefix, case rfc4627_jsonrpc_http:invoke_service_method(AliasPrefix,
Path, Path,
Expand All @@ -106,8 +106,8 @@ handle(AliasPrefix, Req) ->
rfc4627:get_field(ResponseInfo, "http_status_code", 200), rfc4627:get_field(ResponseInfo, "http_status_code", 200),
Headers = [{list_to_binary(K), V} || {K,V} <- ResponseHeaderFields], Headers = [{list_to_binary(K), V} || {K,V} <- ResponseHeaderFields],
RespType = [{<<"Content-Type">>, rfc4627:mime_type()}], RespType = [{<<"Content-Type">>, rfc4627:mime_type()}],
cowboy_http_req:reply(StatusCode, cowboy_req:reply(StatusCode,
Headers ++ RespType, Headers ++ RespType,
ResultEnc, ResultEnc,
Req) Req)
end. end.