aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_static.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cowboy_static.erl')
-rw-r--r--src/cowboy_static.erl18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/cowboy_static.erl b/src/cowboy_static.erl
index ae4e7c0..67cc08f 100644
--- a/src/cowboy_static.erl
+++ b/src/cowboy_static.erl
@@ -19,11 +19,13 @@
-export([malformed_request/2]).
-export([forbidden/2]).
-export([content_types_provided/2]).
+-export([charsets_provided/2]).
-export([resource_exists/2]).
-export([last_modified/2]).
-export([generate_etag/2]).
-export([get_file/2]).
+-type extra_charset() :: {charset, module(), function()} | {charset, binary()}.
-type extra_etag() :: {etag, module(), function()} | {etag, false}.
-type extra_mimetypes() :: {mimetypes, module(), function()}
| {mimetypes, binary() | {binary(), binary(), [{binary(), binary()}]}}.
@@ -322,6 +324,22 @@ content_types_provided(Req, State={Path, _, Extra}) ->
{[{Type, get_file}], Req, State}
end.
+%% Detect the charset of the file.
+
+-spec charsets_provided(Req, State)
+ -> {[binary()], Req, State}
+ when State::state().
+charsets_provided(Req, State={Path, _, Extra}) ->
+ case lists:keyfind(charset, 1, Extra) of
+ %% We simulate the callback not being exported.
+ false ->
+ no_call;
+ {charset, Module, Function} ->
+ {[Module:Function(Path)], Req, State};
+ {charset, Charset} ->
+ {[Charset], Req, State}
+ end.
+
%% Assume the resource doesn't exist if it's not a regular file.
-spec resource_exists(Req, State)