-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27e8121
commit 4b00a11
Showing
7 changed files
with
296 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
It's a secret to everybody. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env escript | ||
%% -*- erlang -*- | ||
%%! -name httpdmaster -pa ./ebin -boot start_sasl -setcookie supersecret | ||
|
||
main(_) -> | ||
etap:plan(unknown), | ||
error_logger:tty(false), | ||
inets:start(), | ||
case (catch start()) of | ||
{'EXIT', Err} -> | ||
io:format("Err ~p~n", [Err]), | ||
etap:bail(); | ||
_ -> | ||
etap:end_tests() | ||
end, | ||
ok. | ||
|
||
start() -> | ||
mochevent:start({mochevent, default}), | ||
os:cmd("for i in `cat /tmp/mochevent.lock`; do kill $i; done"), | ||
os:cmd("./bin/mocheventcnode --daemon --ip 0.0.0.0 --port 5001 --master httpdmaster@`hostname`"), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(get, "http://127.0.0.1:5001/nick", [], []), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("The rain in Spain falls gently on the plain.", "body ok"), | ||
ok | ||
end)(), | ||
|
||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env escript | ||
%% -*- erlang -*- | ||
%%! -name httpdmaster -pa ./ebin -boot start_sasl -setcookie supersecret | ||
|
||
main(_) -> | ||
etap:plan(unknown), | ||
error_logger:tty(false), | ||
inets:start(), | ||
case (catch start()) of | ||
{'EXIT', Err} -> | ||
io:format("Err ~p~n", [Err]), | ||
etap:bail(); | ||
_ -> | ||
etap:end_tests() | ||
end, | ||
ok. | ||
|
||
start() -> | ||
Pid = spawn_link(fun() -> server() end), | ||
register(mochevent_handler, Pid), | ||
|
||
os:cmd("for i in `cat /tmp/mochevent.lock`; do kill $i; done"), | ||
os:cmd("./bin/mocheventcnode --daemon --ip 0.0.0.0 --port 5001 --master httpdmaster@`hostname`"), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(get, "http://127.0.0.1:5001/nick", [], []), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("Received request method was GET", "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(post, "http://127.0.0.1:5001/nick", [], "POST body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("Received request method was POST", "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(put, "http://127.0.0.1:5001/nick", [], "PUT body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("Received request method was PUT", "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(delete, "http://127.0.0.1:5001/nick", [], []), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("Received request method was DELETE", "body ok"), | ||
ok | ||
end)(), | ||
|
||
ok. | ||
|
||
server() -> | ||
receive | ||
{Pid, Id, Method, Uri, Headers, Body} -> | ||
Req = mochevent_request:new(Pid, Id, Method, Uri, {1, 0}, mochiweb_headers:make(Headers), Body), | ||
OutBody = erlang:iolist_to_binary([<<"Received request method was ">>, clean_method(Method)]), | ||
Req:respond({200, [{<<"content-type">>, <<"text/plain">>}], OutBody}) | ||
end, | ||
server(). | ||
|
||
clean_method(0) -> "GET"; | ||
clean_method(1) -> "POST"; | ||
clean_method(3) -> "PUT"; | ||
clean_method(4) -> "DELETE"; | ||
clean_method(_) -> "OTHER". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env escript | ||
%% -*- erlang -*- | ||
%%! -name httpdmaster -pa ./ebin -boot start_sasl -setcookie supersecret | ||
|
||
main(_) -> | ||
etap:plan(unknown), | ||
error_logger:tty(false), | ||
inets:start(), | ||
case (catch start()) of | ||
{'EXIT', Err} -> | ||
io:format("Err ~p~n", [Err]), | ||
etap:bail(); | ||
_ -> | ||
etap:end_tests() | ||
end, | ||
ok. | ||
|
||
start() -> | ||
Pid = spawn_link(fun() -> server() end), | ||
register(mochevent_handler, Pid), | ||
|
||
os:cmd("for i in `cat /tmp/mochevent.lock`; do kill $i; done"), | ||
os:cmd("./bin/mocheventcnode --daemon --ip 0.0.0.0 --port 5001 --master httpdmaster@`hostname`"), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(get, "http://127.0.0.1:5001/nick", [], "GET body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("", "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(post, "http://127.0.0.1:5001/nick", [], "POST body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("POST body", "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(put, "http://127.0.0.1:5001/nick", [], "PUT body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("PUT body", "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(delete, "http://127.0.0.1:5001/nick", [], "DELETE body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("", "body ok"), | ||
ok | ||
end)(), | ||
|
||
ok. | ||
|
||
server() -> | ||
receive | ||
{Pid, Id, Method, Uri, Headers, Body} -> | ||
Req = mochevent_request:new(Pid, Id, Method, Uri, {1, 0}, mochiweb_headers:make(Headers), Body), | ||
OutBody = erlang:iolist_to_binary([<<"Received request method was ">>, clean_method(Method)]), | ||
Req:respond({200, [{<<"content-type">>, <<"text/plain">>}], Body}) | ||
end, | ||
server(). | ||
|
||
clean_method(0) -> "GET"; | ||
clean_method(1) -> "POST"; | ||
clean_method(3) -> "PUT"; | ||
clean_method(4) -> "DELETE"; | ||
clean_method(_) -> "OTHER". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env escript | ||
%% -*- erlang -*- | ||
%%! -name httpdmaster -pa ./ebin -boot start_sasl -setcookie supersecret | ||
|
||
main(_) -> | ||
etap:plan(unknown), | ||
error_logger:tty(false), | ||
inets:start(), | ||
case (catch start()) of | ||
{'EXIT', Err} -> | ||
io:format("Err ~p~n", [Err]), | ||
etap:bail(); | ||
_ -> | ||
etap:end_tests() | ||
end, | ||
ok. | ||
|
||
gen_headers(N) -> | ||
[{"header" ++ integer_to_list(X), "value" ++ integer_to_list(X)} || X <- lists:seq(1, N)]. | ||
|
||
start() -> | ||
Pid = spawn_link(fun() -> server() end), | ||
register(mochevent_handler, Pid), | ||
|
||
os:cmd("for i in `cat /tmp/mochevent.lock`; do kill $i; done"), | ||
os:cmd("./bin/mocheventcnode --daemon --ip 0.0.0.0 --port 5001 --master httpdmaster@`hostname`"), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(get, "http://127.0.0.1:5001/nick", gen_headers(25), "GET body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is(header_body(gen_headers(25)), "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(get, "http://127.0.0.1:5001/nick", gen_headers(51), "GET body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is(header_body(gen_headers(47)), "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(post, "http://127.0.0.1:5001/nick", gen_headers(25), "POST body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is(header_body(gen_headers(25)), "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(put, "http://127.0.0.1:5001/nick", gen_headers(25), "PUT body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is(header_body(gen_headers(25)), "body ok"), | ||
ok | ||
end)(), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(delete, "http://127.0.0.1:5001/nick", gen_headers(25), "DELETE body"), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is(header_body(gen_headers(25)), "body ok"), | ||
ok | ||
end)(), | ||
|
||
ok. | ||
|
||
server() -> | ||
receive | ||
{Pid, Id, Method, Uri, Headers, Body} -> | ||
Req = mochevent_request:new(Pid, Id, Method, Uri, {1, 0}, mochiweb_headers:make(Headers), Body), | ||
OutBody = header_body(Headers), | ||
Req:respond({200, [{<<"content-type">>, <<"text/plain">>}], list_to_binary(OutBody)}) | ||
end, | ||
server(). | ||
|
||
header_body(Headers) -> | ||
lists:foldl( | ||
fun ({"header" ++ _ = K, V}, Str) -> lists:append([Str, K ++ ":" ++ V ++ "\n"]); | ||
(_, Str) -> Str | ||
end, | ||
"", | ||
Headers | ||
). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env escript | ||
%% -*- erlang -*- | ||
%%! -name httpdmaster -pa ./ebin -boot start_sasl -setcookie supersecret | ||
|
||
main(_) -> | ||
etap:plan(unknown), | ||
error_logger:tty(false), | ||
inets:start(), | ||
case (catch start()) of | ||
{'EXIT', Err} -> | ||
io:format("Err ~p~n", [Err]), | ||
etap:bail(); | ||
_ -> | ||
etap:end_tests() | ||
end, | ||
ok. | ||
|
||
start() -> | ||
Pid = spawn_link(fun() -> server() end), | ||
register(mochevent_handler, Pid), | ||
|
||
os:cmd("for i in `cat /tmp/mochevent.lock`; do kill $i; done"), | ||
os:cmd("./bin/mocheventcnode --daemon --ip 0.0.0.0 --port 5001 --master httpdmaster@`hostname`"), | ||
|
||
(fun() -> | ||
Request = etap_web:build_request(get, "http://127.0.0.1:5001/foo.bin", [], []), | ||
Request:status_is(200, "status code ok"), | ||
Request:body_is("It's a secret to everybody.\n", "body ok"), | ||
ok | ||
end)(), | ||
|
||
ok. | ||
|
||
server() -> | ||
receive | ||
{Pid, Id, Method, <<"/foo.bin">>, Headers, Body} -> | ||
Req = mochevent_request:new(Pid, Id, Method, <<"/foo.bin">>, {1, 0}, mochiweb_headers:make(Headers), Body), | ||
{ok, Binary} = file:read_file("foo.bin"), | ||
Req:respond({200, [{<<"content-type">>, <<"application/octet-stream">>}], Binary}) | ||
end, | ||
server(). |