From f5f9f65abbce7625338e721d8fdf6c6c75cb0d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 2 Nov 2013 12:53:16 +0100 Subject: Improve mimetypes code based on cowboy_static usage --- src/cow_mimetypes.erl.src | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/cow_mimetypes.erl.src') diff --git a/src/cow_mimetypes.erl.src b/src/cow_mimetypes.erl.src index c387726..a98c652 100644 --- a/src/cow_mimetypes.erl.src +++ b/src/cow_mimetypes.erl.src @@ -19,41 +19,41 @@ %% @doc Return the mimetype for any file by looking at its extension. --spec all(file:filename_all()) -> binary() | false. +-spec all(file:filename_all()) -> {binary(), binary(), []}. all(Path) -> case filename:extension(Path) of - <<>> -> false; + <<>> -> {<<"application">>, <<"octet-stream">>, []}; << $., Ext/binary >> -> all_ext(Ext) end. %% @doc Return the mimetype for a Web related file by looking at its extension. --spec web(file:filename_all()) -> binary() | false. +-spec web(file:filename_all()) -> {binary(), binary(), []}. web(Path) -> case filename:extension(Path) of - <<>> -> false; + <<>> -> {<<"application">>, <<"octet-stream">>, []}; << $., Ext/binary >> -> web_ext(Ext) end. %% Internal. %% GENERATED -all_ext(_) -> false. - -web_ext(<<"css">>) -> <<"text/css">>; -web_ext(<<"gif">>) -> <<"image/gif">>; -web_ext(<<"html">>) -> <<"text/html">>; -web_ext(<<"htm">>) -> <<"text/html">>; -web_ext(<<"ico">>) -> <<"image/x-icon">>; -web_ext(<<"jpeg">>) -> <<"image/jpeg">>; -web_ext(<<"jpg">>) -> <<"image/jpeg">>; -web_ext(<<"js">>) -> <<"application/javascript">>; -web_ext(<<"mp3">>) -> <<"audio/mpeg">>; -web_ext(<<"mp4">>) -> <<"video/mp4">>; -web_ext(<<"ogg">>) -> <<"audio/ogg">>; -web_ext(<<"ogv">>) -> <<"video/ogg">>; -web_ext(<<"png">>) -> <<"image/png">>; -web_ext(<<"svg">>) -> <<"image/svg+xml">>; -web_ext(<<"wav">>) -> <<"audio/x-wav">>; -web_ext(<<"webm">>) -> <<"video/webm">>; -web_ext(_) -> false. +all_ext(_) -> {<<"application">>, <<"octet-stream">>, []}. + +web_ext(<<"css">>) -> {<<"text">>, <<"css">>, []}; +web_ext(<<"gif">>) -> {<<"image">>, <<"gif">>, []}; +web_ext(<<"html">>) -> {<<"text">>, <<"html">>, []}; +web_ext(<<"htm">>) -> {<<"text">>, <<"html">>, []}; +web_ext(<<"ico">>) -> {<<"image">>, <<"x-icon">>, []}; +web_ext(<<"jpeg">>) -> {<<"image">>, <<"jpeg">>, []}; +web_ext(<<"jpg">>) -> {<<"image">>, <<"jpeg">>, []}; +web_ext(<<"js">>) -> {<<"application">>, <<"javascript">>, []}; +web_ext(<<"mp3">>) -> {<<"audio">>, <<"mpeg">>, []}; +web_ext(<<"mp4">>) -> {<<"video">>, <<"mp4">>, []}; +web_ext(<<"ogg">>) -> {<<"audio">>, <<"ogg">>, []}; +web_ext(<<"ogv">>) -> {<<"video">>, <<"ogg">>, []}; +web_ext(<<"png">>) -> {<<"image">>, <<"png">>, []}; +web_ext(<<"svg">>) -> {<<"image">>, <<"svg+xml">>, []}; +web_ext(<<"wav">>) -> {<<"audio">>, <<"x-wav">>, []}; +web_ext(<<"webm">>) -> {<<"video">>, <<"webm">>, []}; +web_ext(_) -> {<<"application">>, <<"octet-stream">>, []}. -- cgit v1.2.3