Permalink
Browse files

response type fixed

  • Loading branch information...
1 parent 3855199 commit 2a8a631cd6b16b0f6a98c2f75a495efd68df4057 @evolchek evolchek committed with Mar 19, 2011
Showing with 11 additions and 2 deletions.
  1. +1 −1 src/rfc4627_jsonrpc_inets.erl
  2. +10 −1 src/rfc4627_jsonrpc_mochiweb.erl
View
2 src/rfc4627_jsonrpc_inets.erl
@@ -161,7 +161,7 @@ do_rpc(#mod{init_data = #init_data{peername = {PeerPort, PeerName}},
{proceed, [{response, {response,
[{code, 200},
{content_length, integer_to_list(length(ResultEnc))},
- {content_type, "text/plain"}%rfc4627:mime_type()}
+ {content_type, rfc4627:mime_type()}
| Headers],
ResultEnc}} | OldData]}
end.
View
11 src/rfc4627_jsonrpc_mochiweb.erl
@@ -99,8 +99,17 @@ handle(AliasPrefix, Req) ->
no_match ->
no_match;
{ok, ResultEnc, ResponseInfo} ->
+ DefaultType = rfc4627:mime_type(),
+ RespType = case Req:accepts_content_type(DefaultType) of
+ true -> DefaultType;
+ false ->
+ case Req:accepts_content_type("text/plain") of
+ true -> "text/plain";
+ false -> DefaultType
+ end
+ end,
{obj, ResponseHeaderFields} =
rfc4627:get_field(ResponseInfo, "http_headers", {obj, []}),
Headers = [{K, binary_to_list(V)} || {K,V} <- ResponseHeaderFields],
- {ok, {200, Headers ++ [{"Content-type", "text/plain"}], ResultEnc}}
+ {ok, {200, Headers ++ [{"Content-type", RespType}], ResultEnc}}
end.

0 comments on commit 2a8a631

Please sign in to comment.