0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

add utf-8 support to example file_server

This commit is contained in:
lin 2023-02-15 00:30:18 +08:00
parent 30ee75cea1
commit ade34b2bf3
3 changed files with 23 additions and 3 deletions

View file

@ -0,0 +1,8 @@
<html>
<head>
<meta charset='utf-8'>
</head>
<body>
你好!
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<meta charset='utf-8'>
</head>
<body>
你好!
</body>
</html>

View file

@ -32,12 +32,12 @@ content_types_provided(Req, State) ->
], Req, State}.
list_json(Req, {Path, Fs}) ->
Files = [ <<(list_to_binary(F))/binary>> || F <- Fs ],
Files = [ <<(unicode_to_iolist(F))/binary>> || F <- Fs ],
{jsx:encode(Files), Req, Path}.
list_html(Req, {Path, Fs}) ->
Body = [[ links(Path, F) || F <- [".."|Fs] ]],
HTML = [<<"<!DOCTYPE html><html><head><title>Index</title></head>",
Body = [[ links(Path, unicode_to_iolist(F)) || F <- [".."|Fs] ]],
HTML = [<<"<!DOCTYPE html><html><head><meta charset='utf-8'<title>Index</title></head>",
"<body>">>, Body, <<"</body></html>\n">>],
{HTML, Req, Path}.
@ -51,3 +51,7 @@ links(<<>>, File) ->
["<a href='/", File, "'>", File, "</a><br>\n"];
links(Prefix, File) ->
["<a href='/", Prefix, File, "'>", File, "</a><br>\n"].
unicode_to_iolist(UniString) ->
binary_to_list(unicode:characters_to_binary(UniString)).