Skip to content

Commit

Permalink
Accept more mime types as text for charset negotiation (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Jun 20, 2023
1 parent 8d470e7 commit 21ac6ff
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/cowmachine_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,28 @@ default(_, _Context) ->
ContentType :: cow_http_hd:media_type(),
Result :: boolean().
is_text({<<"text">>, _, _}) -> true;
is_text({<<"application">>, <<"json">>, _}) -> true;
is_text({<<"application">>, <<"ld+json">>, _}) -> true;
is_text({<<"application">>, <<"x-javascript">>, _}) -> true;
is_text({<<"application">>, <<"javascript">>, _}) -> true;
is_text({<<"application">>, <<"xhtml">>, _}) -> true;
is_text({<<"application">>, <<"xhtml+xml">>, _}) -> true;
is_text({<<"application">>, <<"xml">>, _}) -> true;
is_text(_Mime) -> false.

is_text({<<"application">>, Sub, _}) ->
case binary:split(Sub, <<"+">>) of
[_, <<"json">>] -> true;
[_, <<"xml">>] -> true;
_ -> false
end;
is_text(_) ->
false.

%% @TODO Re-add logging code

%% @doc Export and run function `Fun'.

-spec do(Fun, State, Context) -> Result when
Fun :: atom(),
State :: cmstate(),
State :: cmstate(),
Context :: cowmachine_req:context(),
Result :: {ContentType, Context},
ContentType :: cow_http_hd:media_type().
Expand All @@ -168,8 +176,8 @@ do(Fun, #cmstate{ controller = Controller }, Context) when is_atom(Fun) ->
%% @doc Export and process `State' with `Context'.

-spec do_process(ContentType, State, Context) -> Result when
ContentType :: cow_http_hd:media_type(),
State :: cmstate(),
ContentType :: cow_http_hd:media_type(),
State :: cmstate(),
Context :: cowmachine_req:context(),
Result :: {Res, Context},
Res :: boolean() | cowmachine_req:halt() | {error, any(), any()} | {error, any()} |
Expand Down

0 comments on commit 21ac6ff

Please sign in to comment.