From 98b3f85740cd1eb3ca7d660570d48cd271e20e72 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Tue, 18 Jan 2022 18:20:44 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/eWSrv.app.src | 2 +- src/test/elli_handover_tests.erl | 52 -------------- src/test/elli_metrics_middleware.erl | 34 --------- src/test/elli_middleware_tests.erl | 102 --------------------------- 5 files changed, 2 insertions(+), 190 deletions(-) delete mode 100644 src/test/elli_handover_tests.erl delete mode 100644 src/test/elli_metrics_middleware.erl delete mode 100644 src/test/elli_middleware_tests.erl diff --git a/README.md b/README.md index 7cfd96e..8ce8cfb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ eWSrv ===== -An erlang web server +An erlang's http1.1 server Build ----- diff --git a/src/eWSrv.app.src b/src/eWSrv.app.src index f8bccc6..98e23c4 100644 --- a/src/eWSrv.app.src +++ b/src/eWSrv.app.src @@ -1,5 +1,5 @@ {application, eWSrv, - [{description, "erlang web server"}, + [{description, "erlang http1.1 server"}, {vsn, "0.1.0"}, {registered, []}, {mod, {eWSrv_app, []}}, diff --git a/src/test/elli_handover_tests.erl b/src/test/elli_handover_tests.erl deleted file mode 100644 index c49a568..0000000 --- a/src/test/elli_handover_tests.erl +++ /dev/null @@ -1,52 +0,0 @@ --module(elli_handover_tests). --include_lib("eunit/include/eunit.hrl"). --include("elli_test.hrl"). - -elli_test_() -> - {setup, - fun setup/0, fun teardown/1, - [ - ?_test(hello_world()), - ?_test(echo()) - ]}. - - - -setup() -> - application:start(crypto), - application:start(public_key), - application:start(ssl), - {ok, _} = application:ensure_all_started(hackney), - - Config = [ - {mods, [ - {elli_example_callback_handover, []} - ]} - ], - - {ok, P} = elli:start_link([{callback, elli_middleware}, - {callback_args, Config}, - {port, 3003}]), - unlink(P), - [P]. - -teardown(Pids) -> - [elli:stop(P) || P <- Pids]. - - -%% -%% INTEGRATION TESTS -%% Uses hackney to actually call Elli over the network -%% - -hello_world() -> - Response = hackney:get("http://localhost:3003/hello/world"), - ?assertMatch(200, status(Response)), - ?assertMatch([{<<"Connection">>, <<"close">>}, - {<<"Content-Length">>, <<"12">>}], headers(Response)), - ?assertMatch(<<"Hello World!">>, body(Response)). - -echo() -> - Response = hackney:get("http://localhost:3003/hello?name=knut"), - ?assertMatch(200, status(Response)), - ?assertMatch(<<"Hello knut">>, body(Response)). diff --git a/src/test/elli_metrics_middleware.erl b/src/test/elli_metrics_middleware.erl deleted file mode 100644 index eed1c26..0000000 --- a/src/test/elli_metrics_middleware.erl +++ /dev/null @@ -1,34 +0,0 @@ --module(elli_metrics_middleware). --export([init/2, preprocess/2, handle/2, postprocess/3, handle_event/3]). --behaviour(wsHer). - - -%% -%% ELLI -%% - -init(_Req, _Args) -> - ignore. - -preprocess(Req, _Args) -> - Req. - -handle(_Req, _Args) -> - ignore. - -postprocess(_Req, Res, _Args) -> - Res. - - -%% -%% ELLI EVENT CALLBACKS -%% - -handle_event(request_complete, [_Req, _C, _Hs, _B, {Timings, Sizes}], _) -> - ets:insert(elli_stat_table, {timings, Timings}), - ets:insert(elli_stat_table, {sizes, Sizes}); -handle_event(chunk_complete, [_Req, _C, _Hs, _B, {Timings, Sizes}], _) -> - ets:insert(elli_stat_table, {timings, Timings}), - ets:insert(elli_stat_table, {sizes, Sizes}); -handle_event(_Event, _Data, _Args) -> - ok. diff --git a/src/test/elli_middleware_tests.erl b/src/test/elli_middleware_tests.erl deleted file mode 100644 index 20f6635..0000000 --- a/src/test/elli_middleware_tests.erl +++ /dev/null @@ -1,102 +0,0 @@ --module(elli_middleware_tests). --include_lib("eunit/include/eunit.hrl"). --include("elli_test.hrl"). - -elli_test_() -> - {setup, - fun setup/0, fun teardown/1, - [ - ?_test(hello_world()), - ?_test(short_circuit()), - ?_test(compress()), - ?_test(no_callbacks()) - ]}. - - -%% -%% TESTS -%% - -short_circuit() -> - URL = "http://localhost:3002/middleware/short-circuit", - Response = hackney:get(URL), - ?assertMatch(<<"short circuit!">>, body(Response)). - -hello_world() -> - URL = "http://localhost:3002/hello/world", - Response = hackney:get(URL), - ?assertMatch(<<"Hello World!">>, body(Response)). - -compress() -> - Url = "http://localhost:3002/compressed", - Headers = [{<<"Accept-Encoding">>, <<"gzip">>}], - Response = hackney:get(Url, Headers), - ?assertHeadersEqual([{<<"Connection">>, <<"Keep-Alive">>}, - {<<"Content-Encoding">>, <<"gzip">>}, - {<<"Content-Length">>, <<"41">>}], - headers(Response)), - ?assertEqual(binary:copy(<<"Hello World!">>, 86), - zlib:gunzip(body(Response))), - Response1 = hackney:get("http://localhost:3002/compressed"), - ?assertHeadersEqual([{<<"Connection">>, <<"Keep-Alive">>}, - {<<"Content-Length">>, <<"1032">>}], - headers(Response1)), - ?assertEqual(iolist_to_binary(lists:duplicate(86, "Hello World!")), - body(Response1)), - Url2 = "http://localhost:3002/compressed-io_list", - Headers2 = [{<<"Accept-Encoding">>, <<"gzip">>}], - Response2 = hackney:get(Url2, Headers2), - ?assertMatch(200, status(Response2)), - ?assertHeadersEqual([{<<"Connection">>, <<"Keep-Alive">>}, - {<<"Content-Encoding">>, <<"gzip">>}, - {<<"Content-Length">>, <<"41">>}], - headers(Response2)), - ?assertEqual(binary:copy(<<"Hello World!">>, 86), - zlib:gunzip(body(Response2))), - Response3 = hackney:request("http://localhost:3002/compressed-io_list"), - ?assertMatch(200, status(Response3)), - ?assertHeadersEqual([{<<"Connection">>, <<"Keep-Alive">>}, - {<<"Content-Length">>, <<"1032">>}], - headers(Response3)), - ?assertEqual(iolist_to_binary(lists:duplicate(86, "Hello World!")), - body(Response3)). - -no_callbacks() -> - Response = hackney:get("http://localhost:3004/whatever"), - ?assertMatch(404, status(Response)), - ?assertMatch(<<"Not Found">>, body(Response)). - - -%% -%% HELPERS -%% - -setup() -> - application:start(crypto), - application:start(public_key), - application:start(ssl), - {ok, _} = application:ensure_all_started(hackney), - - Config = [ - {mods, [ - {elli_access_log, [{name, elli_syslog}, - {ip, "127.0.0.1"}, - {port, 514}]}, - {elli_example_middleware, []}, - {elli_middleware_compress, []}, - {elli_example_callback, []} - ]} - ], - - {ok, P1} = elli:start_link([{callback, elli_middleware}, - {callback_args, Config}, - {port, 3002}]), - unlink(P1), - {ok, P2} = elli:start_link([{callback, elli_middleware}, - {callback_args, [{mods, []}]}, - {port, 3004}]), - unlink(P2), - [P1, P2]. - -teardown(Pids) -> - [elli:stop(P) || P <- Pids].