Skip to content

Commit

Permalink
allow expires type/*
Browse files Browse the repository at this point in the history
  • Loading branch information
andreineculau committed Mar 22, 2015
1 parent eadc686 commit 26a608d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
38 changes: 31 additions & 7 deletions src/yaws.erl
Expand Up @@ -95,7 +95,7 @@
month/1, mk2/1, home/0, arg_rewrite/1, to_lowerchar/1, to_lower/1,
funreverse/2, is_prefix/2, split_sep/2, join_sep/2, accepts_gzip/2,
upto_char/2, deepmap/2, ticker/2, ticker/3,
parse_qvalue/1, parse_auth/1]).
parse_qvalue/1, parse_auth/1, parse_mimetype/1]).

-export([outh_set_status_code/1,
outh_set_non_cacheable/1,
Expand Down Expand Up @@ -1511,15 +1511,28 @@ make_expires_header("*/*", FI) ->
{_MimeType, Type, TTL} -> make_expires_header(Type, TTL, FI);
false -> {undefined, undefined}
end;
make_expires_header(MimeType0, FI) ->
make_expires_header(MT0, FI) ->
SC = get(sc),
%% Use split_sep to remove charset
case yaws:split_sep(MimeType0, $;) of
case yaws:split_sep(MT0, $;) of
[] -> {undefined, undefined};
[MimeType1|_] ->
case lists:keyfind(MimeType1, 1, SC#sconf.expires) of
{MimeType1, Type, TTL} -> make_expires_header(Type, TTL, FI);
false -> make_expires_header("*/*", FI)
[MT1|_] ->
case lists:keyfind(MT1, 1, SC#sconf.expires) of
{MT1, Type, TTL} ->
make_expires_header(Type, TTL, FI);
false ->
case parse_mimetype(MT1) of
{ok, Type, _Subtype} ->
MT2 = Type ++ "/*",
case lists:keyfind(MT2, 1, SC#sconf.expires) of
{MT2, Type, TTL} ->
make_expires_header(Type, TTL, FI);
false ->
make_expires_header("*/*", FI)
end;
_Error ->
make_expires_header("*/*", FI)
end
end
end.

Expand Down Expand Up @@ -2403,6 +2416,17 @@ parse_auth(Orig) ->
{undefined, undefined, Orig}.


parse_mimetype(MimeType) ->
Res = re:run(MimeType, "^([-\\w\+]+)/([-\\w\+\.]+|\\*)$",
[{capture, all_but_first, list}]),
case Res of
{match, [Type,SubType]} ->
{ok, Type, SubType};
nomatch ->
{error, "Invalid MimeType"}
end.


decode_base64([]) ->
[];
decode_base64(Auth64) ->
Expand Down
12 changes: 5 additions & 7 deletions src/yaws_config.erl
Expand Up @@ -2655,15 +2655,13 @@ parse_compressible_mime_types(["defaults"|Rest], Acc) ->
parse_compressible_mime_types([',' | Rest], Acc) ->
parse_compressible_mime_types(Rest, Acc);
parse_compressible_mime_types([MimeType | Rest], Acc) ->
Res = re:run(MimeType, "^([-\\w\+]+)/([-\\w\+\.]+|\\*)$",
[{capture, all_but_first, list}]),
case Res of
{match, [Type,"*"]} ->
case yaws:parse_mimetype(MimeType) of
{ok, Type, "*"} ->
parse_compressible_mime_types(Rest, [{Type, all}|Acc]);
{match, [Type,SubType]} ->
{ok, Type, SubType} ->
parse_compressible_mime_types(Rest, [{Type, SubType}|Acc]);
nomatch ->
{error, "Invalid MimeType"}
Error ->
Error
end;
parse_compressible_mime_types([], Acc) ->
{ok, Acc}.
Expand Down

0 comments on commit 26a608d

Please sign in to comment.