aboutsummaryrefslogtreecommitdiffstats
path: root/examples/file_server
diff options
context:
space:
mode:
Diffstat (limited to 'examples/file_server')
-rw-r--r--examples/file_server/Makefile2
-rw-r--r--examples/file_server/priv/中文/中文.html8
-rw-r--r--examples/file_server/src/directory_h.erl8
-rw-r--r--examples/file_server/src/file_server_app.erl3
4 files changed, 18 insertions, 3 deletions
diff --git a/examples/file_server/Makefile b/examples/file_server/Makefile
index 7efa6ef..df8f311 100644
--- a/examples/file_server/Makefile
+++ b/examples/file_server/Makefile
@@ -5,4 +5,6 @@ PROJECT_VERSION = 1
DEPS = cowboy jsx
dep_cowboy_commit = master
+REL_DEPS = relx
+
include ../../erlang.mk
diff --git a/examples/file_server/priv/中文/中文.html b/examples/file_server/priv/中文/中文.html
new file mode 100644
index 0000000..43ca75f
--- /dev/null
+++ b/examples/file_server/priv/中文/中文.html
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <meta charset='utf-8'>
+ </head>
+ <body>
+ 中文!
+ </body>
+</html>
diff --git a/examples/file_server/src/directory_h.erl b/examples/file_server/src/directory_h.erl
index 66e1466..7d7bd9a 100644
--- a/examples/file_server/src/directory_h.erl
+++ b/examples/file_server/src/directory_h.erl
@@ -8,6 +8,7 @@
-export([allowed_methods/2]).
-export([resource_exists/2]).
-export([content_types_provided/2]).
+-export([charsets_provided/2]).
%% Callback Callbacks
-export([list_json/2]).
@@ -31,12 +32,15 @@ content_types_provided(Req, State) ->
{{<<"application">>, <<"json">>, []}, list_json}
], Req, State}.
+charsets_provided(Req, State) ->
+ {[<<"utf-8">>], Req, State}.
+
list_json(Req, {Path, Fs}) ->
- Files = [ <<(list_to_binary(F))/binary>> || F <- Fs ],
+ Files = [unicode:characters_to_binary(F) || F <- Fs],
{jsx:encode(Files), Req, Path}.
list_html(Req, {Path, Fs}) ->
- Body = [[ links(Path, F) || F <- [".."|Fs] ]],
+ Body = [[links(Path, unicode:characters_to_binary(F)) || F <- [".."|Fs]]],
HTML = [<<"<!DOCTYPE html><html><head><title>Index</title></head>",
"<body>">>, Body, <<"</body></html>\n">>],
{HTML, Req, Path}.
diff --git a/examples/file_server/src/file_server_app.erl b/examples/file_server/src/file_server_app.erl
index 17e73b2..0ba8f6c 100644
--- a/examples/file_server/src/file_server_app.erl
+++ b/examples/file_server/src/file_server_app.erl
@@ -15,7 +15,8 @@ start(_Type, _Args) ->
{'_', [
{"/[...]", cowboy_static, {priv_dir, file_server, "", [
{mimetypes, cow_mimetypes, all},
- {dir_handler, directory_h}
+ {dir_handler, directory_h},
+ {charset, <<"utf-8">>}
]}}
]}
]),