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

LH: I have fixed issues in the PR and incorporated changes
from a sister PR by @djankovic (git author: Dom J). I also
made sure the UTF-8 files were readable without Chinese
fonts and added their downloading to the examples test suite.
This commit is contained in:
lin 2023-02-15 00:30:18 +08:00 committed by Loïc Hoguin
parent 32594a5199
commit 4f26d6a573
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
4 changed files with 20 additions and 4 deletions

View file

@ -372,13 +372,16 @@ file_server(Config) ->
do_file_server(Transport, Protocol, Config) ->
%% Directory.
{200, DirHeaders, <<"<!DOCTYPE html><html>", _/bits >>} = do_get(Transport, Protocol, "/", Config),
{_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, DirHeaders),
{_, <<"text/html; charset=utf-8">>} = lists:keyfind(<<"content-type">>, 1, DirHeaders),
_ = do_rest_get(Transport, Protocol, "/", <<"application/json">>, undefined, Config),
%% Files.
{200, _, _} = do_get(Transport, Protocol, "/small.mp4", Config),
{200, _, _} = do_get(Transport, Protocol, "/small.ogv", Config),
{200, _, _} = do_get(Transport, Protocol, "/test.txt", Config),
{200, _, _} = do_get(Transport, Protocol, "/video.html", Config),
{200, _, _} = do_get(Transport, Protocol,
["/", cow_uri:urlencode(<<"中文"/utf8>>), "/", cow_uri:urlencode(<<"中文.html"/utf8>>)],
Config),
ok.
%% Markdown middleware.