aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/http_SUITE.erl')
-rw-r--r--test/http_SUITE.erl31
1 files changed, 23 insertions, 8 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index 74d24b6..bad91a8 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -1,4 +1,5 @@
%% Copyright (c) 2011, Loïc Hoguin <[email protected]>
+%% Copyright (c) 2011, Anthony Ramine <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -23,7 +24,7 @@
pipeline/1, raw/1, set_resp_header/1, set_resp_overwrite/1,
set_resp_body/1, stream_body_set_resp/1, response_as_req/1,
static_mimetypes_function/1, static_attribute_etag/1,
- static_function_etag/1]). %% http.
+ static_function_etag/1, multipart/1]). %% http.
-export([http_200/1, http_404/1, handler_errors/1,
file_200/1, file_403/1, dir_403/1, file_404/1,
file_400/1]). %% http and https.
@@ -43,7 +44,7 @@ groups() ->
set_resp_header, set_resp_overwrite,
set_resp_body, response_as_req, stream_body_set_resp,
static_mimetypes_function, static_attribute_etag,
- static_function_etag] ++ BaseTests},
+ static_function_etag, multipart] ++ BaseTests},
{https, [], BaseTests},
{misc, [], [http_10_hostless]},
{rest, [], [rest_simple, rest_keepalive, rest_keepalive_post]}].
@@ -146,6 +147,7 @@ init_http_dispatch(Config) ->
{[<<"static_function_etag">>, '...'], cowboy_http_static,
[{directory, ?config(static_dir, Config)},
{etag, {fun static_function_etag/2, etag_data}}]},
+ {[<<"multipart">>], http_handler_multipart, []},
{[], http_handler, []}
]}
].
@@ -238,6 +240,24 @@ max_keepalive_loop(Socket, N) ->
end,
keepalive_nl_loop(Socket, N - 1).
+multipart(Config) ->
+ Url = build_url("/multipart", Config),
+ Body = <<
+ "This is a preamble."
+ "\r\n--OHai\r\nX-Name:answer\r\n\r\n42"
+ "\r\n--OHai\r\nServer:Cowboy\r\n\r\nIt rocks!\r\n"
+ "\r\n--OHai--"
+ "This is an epiloque."
+ >>,
+ Request = {Url, [], "multipart/x-makes-no-sense; boundary=OHai", Body},
+ {ok, {{"HTTP/1.1", 200, "OK"}, _Headers, Response}} =
+ httpc:request(post, Request, [], [{body_format, binary}]),
+ Parts = binary_to_term(Response),
+ Parts = [
+ {[{<<"X-Name">>, <<"answer">>}], <<"42">>},
+ {[{'Server', <<"Cowboy">>}], <<"It rocks!\r\n">>}
+ ].
+
nc_rand(Config) ->
nc_reqs(Config, "/dev/urandom").
@@ -576,23 +596,18 @@ rest_keepalive_post(Config) ->
rest_keepalive_post_loop(_Socket, 0, _) ->
ok;
rest_keepalive_post_loop(Socket, N, simple_post) ->
- ct:print("simple_post~n"),
ok = gen_tcp:send(Socket, "POST /simple_post HTTP/1.1\r\n"
"Host: localhost\r\nConnection: keep-alive\r\n"
"Content-Length: 5\r\nContent-Type: text/plain\r\n\r\n12345"),
{ok, Data} = gen_tcp:recv(Socket, 0, 6000),
- ct:print("data ~p~n", [Data]),
- {0, 12} = binary:match(Data, <<"HTTP/1.1 200">>),
+ {0, 12} = binary:match(Data, <<"HTTP/1.1 303">>),
nomatch = binary:match(Data, <<"Connection: close">>),
rest_keepalive_post_loop(Socket, N - 1, forbidden_post);
rest_keepalive_post_loop(Socket, N, forbidden_post) ->
- ct:print("forbidden~n"),
ok = gen_tcp:send(Socket, "POST /forbidden_post HTTP/1.1\r\n"
"Host: localhost\r\nConnection: keep-alive\r\n"
"Content-Length: 5\r\nContent-Type: text/plain\r\n\r\n12345"),
{ok, Data} = gen_tcp:recv(Socket, 0, 6000),
- ct:print("data ~p~n", [Data]),
{0, 12} = binary:match(Data, <<"HTTP/1.1 403">>),
nomatch = binary:match(Data, <<"Connection: close">>),
rest_keepalive_post_loop(Socket, N - 1, simple_post).
-