From 571719a164326eebdc792b43170fe27f123aac0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 2 Nov 2018 15:31:54 +0100 Subject: Add a charset option to cowboy_static --- doc/src/manual/cowboy_static.asciidoc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'doc/src/manual/cowboy_static.asciidoc') diff --git a/doc/src/manual/cowboy_static.asciidoc b/doc/src/manual/cowboy_static.asciidoc index a0069da..0e131dd 100644 --- a/doc/src/manual/cowboy_static.asciidoc +++ b/doc/src/manual/cowboy_static.asciidoc @@ -27,7 +27,10 @@ opts() :: {priv_file, App, Path} App :: atom() Path :: binary() | string() -Extra :: [Etag | Mimetypes] +Extra :: [Charset | Etag | Mimetypes] + +Charset :: {charset, module(), function()} + | {charset, binary()} Etag :: {etag, module(), function()} | {etag, false} @@ -72,6 +75,20 @@ current directory. The extra options allow you to define how the etag should be calculated and how the MIME type of files should be detected. +By default the static handler will not send a charset with +the response. You can provide a specific charset that will +be used for all files using the text media type, or provide +a module and function that will be called when needed: + +[source,erlang] +---- +detect_charset(Path :: binary()) -> Charset :: binary() +---- + +A charset must always be returned even if it doesn't make +sense considering the media type of the file. A good default +is `<<"utf-8">>`. + By default the static handler will generate an etag based on the size and modification time of the file. You may disable the etag entirely with `{etag, false}` or provide a module @@ -112,6 +129,7 @@ when it fails to detect a file's MIME type. == Changelog +* *2.6*: The `charset` extra option was added. * *1.0*: Handler introduced. == Examples -- cgit v1.2.3