From be419c5c70dd17269d851a2a291ad10453442da9 Mon Sep 17 00:00:00 2001 From: Dom J <6401646+djankovic@users.noreply.github.com> Date: Fri, 10 Feb 2023 21:29:58 +0100 Subject: [PATCH] Add UTF-8 support to the file_server example --- examples/file_server/src/directory_h.erl | 8 ++++++-- examples/file_server/src/file_server_app.erl | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/file_server/src/directory_h.erl b/examples/file_server/src/directory_h.erl index 66e1466b..4eb9720f 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))/binary>> || 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 = [<<"