Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Add test for unexpected 100 Continue response.
Browse files Browse the repository at this point in the history
--HG--
branch : 1.2
  • Loading branch information
oscarh committed Jan 21, 2010
1 parent eeb3277 commit 1f3f075
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/lhttpc_tests.erl
Expand Up @@ -65,6 +65,7 @@ tcp_test_() ->
?_test(pre_1_1_server_keep_alive()),
?_test(simple_put()),
?_test(post()),
?_test(post_100_continue()),
?_test(bad_url()),
?_test(persistent_connection()),
?_test(request_timeout()),
Expand Down Expand Up @@ -230,6 +231,22 @@ post() ->
?assertEqual("OK", ReasonPhrase),
?assertEqual(iolist_to_binary(Body), body(Response)).

post_100_continue() ->
Port = start(gen_tcp, [fun copy_body_100_continue/5]),
URL = url(Port, "/post"),
{X, Y, Z} = now(),
Body = [
"This is a rather simple post :)",
integer_to_list(X),
integer_to_list(Y),
integer_to_list(Z)
],
{ok, Response} = lhttpc:request(URL, "POST", [], Body, 1000),
{StatusCode, ReasonPhrase} = status(Response),
?assertEqual(200, StatusCode),
?assertEqual("OK", ReasonPhrase),
?assertEqual(iolist_to_binary(Body), body(Response)).

bad_url() ->
?assertError(_, lhttpc:request(ost, "GET", [], 100)).

Expand Down Expand Up @@ -418,6 +435,18 @@ copy_body(Module, Socket, _, _, Body) ->
]
).

copy_body_100_continue(Module, Socket, _, _, Body) ->
Module:send(
Socket,
[
"HTTP/1.1 100 Continue\r\n\r\n"
"HTTP/1.1 200 OK\r\n"
"Content-type: text/plain\r\nContent-length: "
++ integer_to_list(size(Body)) ++ "\r\n\r\n",
Body
]
).

respond_and_close(Module, Socket, _, _, Body) ->
Pid = list_to_pid(binary_to_list(Body)),
Module:send(
Expand Down

0 comments on commit 1f3f075

Please sign in to comment.