diff options
author | Loïc Hoguin <[email protected]> | 2018-11-02 15:31:54 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-11-02 15:36:41 +0100 |
commit | 571719a164326eebdc792b43170fe27f123aac0d (patch) | |
tree | 59b5bb3ed45e1642bc772a66a11a39648df6a7b4 /src | |
parent | 9569043bddd2ab1c31e198beb901fcba046b95c2 (diff) | |
download | cowboy-571719a164326eebdc792b43170fe27f123aac0d.tar.gz cowboy-571719a164326eebdc792b43170fe27f123aac0d.tar.bz2 cowboy-571719a164326eebdc792b43170fe27f123aac0d.zip |
Add a charset option to cowboy_static
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_static.erl | 18 |
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) |