0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 20:50:24 +00:00

Add default CTP: "text/html" maps to to_html

This commit is contained in:
Seletskiy Stanislav 2013-04-26 18:34:01 +07:00
parent 97b8401c45
commit f316b47d13
3 changed files with 39 additions and 1 deletions

View file

@ -219,7 +219,19 @@ options(Req, State) ->
content_types_provided(Req, State) ->
case call(Req, State, content_types_provided) of
no_call ->
not_acceptable(Req, State);
State2 = State#state{
content_types_p=[{{<<"text">>, <<"html">>, '*'}, to_html}]},
case cowboy_req:parse_header(<<"accept">>, Req) of
{error, badarg} ->
respond(Req, State2, 400);
{ok, undefined, Req2} ->
languages_provided(
cowboy_req:set_meta(media_type, {<<"text">>, <<"html">>, []}, Req2),
State2#state{content_type_a={{<<"text">>, <<"html">>, []}, to_html}});
{ok, Accept, Req2} ->
Accept2 = prioritize_accept(Accept),
choose_media_type(Req2, State2, Accept2)
end;
{halt, Req2, HandlerState} ->
terminate(Req2, State#state{handler_state=HandlerState});
{[], Req2, HandlerState} ->