Permalink
Browse files

Add test for unexpected 100 Continue response.

--HG--
branch : 1.2
  • Loading branch information...
1 parent eeb3277 commit 1f3f0751a9670a651b54ceeb0183e53ce5766aa8 @oscarh oscarh committed Jan 21, 2010
Showing with 29 additions and 0 deletions.
  1. +29 −0 test/lhttpc_tests.erl
View
@@ -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()),
@@ -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)).
@@ -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(

0 comments on commit 1f3f075

Please sign in to comment.