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

Adobe-valid MIME type for crossdomain.xml #118

Merged
merged 2 commits into from
Nov 13, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/mochiweb_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,16 @@ urlsplit_query([C | Rest], Acc) ->
%% @spec guess_mime(string()) -> string()
%% @doc Guess the mime type of a file by the extension of its filename.
guess_mime(File) ->
case mochiweb_mime:from_extension(filename:extension(File)) of
undefined ->
"text/plain";
Mime ->
Mime
case filename:basename(File) of
"crossdomain.xml" ->
"text/x-cross-domain-policy";
Name ->
case mochiweb_mime:from_extension(filename:extension(Name)) of
undefined ->
"text/plain";
Mime ->
Mime
end
end.

%% @spec parse_header(string()) -> {Type, [{K, V}]}
Expand Down Expand Up @@ -686,12 +691,14 @@ parse_header_test() ->
ok.

guess_mime_test() ->
"text/plain" = guess_mime(""),
"text/plain" = guess_mime(".text"),
"application/zip" = guess_mime(".zip"),
"application/zip" = guess_mime("x.zip"),
"text/html" = guess_mime("x.html"),
"application/xhtml+xml" = guess_mime("x.xhtml"),
?assertEqual("text/plain", guess_mime("")),
?assertEqual("text/plain", guess_mime(".text")),
?assertEqual("application/zip", guess_mime(".zip")),
?assertEqual("application/zip", guess_mime("x.zip")),
?assertEqual("text/html", guess_mime("x.html")),
?assertEqual("application/xhtml+xml", guess_mime("x.xhtml")),
?assertEqual("text/x-cross-domain-policy", guess_mime("crossdomain.xml")),
?assertEqual("text/x-cross-domain-policy", guess_mime("www/crossdomain.xml")),
ok.

path_split_test() ->
Expand Down