Commits

Oscar Hellström  committed 85562aa

Tests for HEAD, OPTIONS, DELETE methods with and without content

  • Participants
  • Parent commits d58a4c9

Comments (0)

Files changed (1)

File test/lhttpc_tests.erl

             ?_test(get_with_mandatory_hdrs()),
             ?_test(no_content_length()),
             ?_test(no_content_length_1_0()),
+            ?_test(simple_head()),
+            ?_test(simple_head_atom()),
+            ?_test(delete_no_content()),
+            ?_test(delete_content()),
+            ?_test(options_content()),
+            ?_test(options_no_content()),
             ?_test(server_connection_close()),
             ?_test(client_connection_close()),
             ?_test(pre_1_1_server_connection()),
     ?assertEqual({200, "OK"}, status(Response)),
     ?assertEqual(<<?DEFAULT_STRING>>, body(Response)).
 
+simple_head() ->
+    Port = start(gen_tcp, [fun head_response/5]),
+    URL = url(Port, "/HEAD"),
+    {ok, Response} = lhttpc:request(URL, "HEAD", [], 1000),
+    ?assertEqual({200, "OK"}, status(Response)),
+    ?assertEqual(<<>>, body(Response)).
+
+simple_head_atom() ->
+    Port = start(gen_tcp, [fun head_response/5]),
+    URL = url(Port, "/head"),
+    {ok, Response} = lhttpc:request(URL, head, [], 1000),
+    ?assertEqual({200, "OK"}, status(Response)),
+    ?assertEqual(<<>>, body(Response)).
+
+delete_no_content() ->
+    Port = start(gen_tcp, [fun no_content_response/5]),
+    URL = url(Port, "/delete_no_content"),
+    {ok, Response} = lhttpc:request(URL, delete, [], 1000),
+    ?assertEqual({204, "OK"}, status(Response)),
+    ?assertEqual(<<>>, body(Response)).
+
+delete_content() ->
+    Port = start(gen_tcp, [fun simple_response/5]),
+    URL = url(Port, "/delete_content"),
+    {ok, Response} = lhttpc:request(URL, "DELETE", [], 1000),
+    ?assertEqual({200, "OK"}, status(Response)),
+    ?assertEqual(<<?DEFAULT_STRING>>, body(Response)).
+
+options_no_content() ->
+    Port = start(gen_tcp, [fun head_response/5]),
+    URL = url(Port, "/options_no_content"),
+    {ok, Response} = lhttpc:request(URL, "OPTIONS", [], 1000),
+    ?assertEqual({200, "OK"}, status(Response)),
+    ?assertEqual(<<>>, body(Response)).
+
+options_content() ->
+    Port = start(gen_tcp, [fun simple_response/5]),
+    URL = url(Port, "/options_content"),
+    {ok, Response} = lhttpc:request(URL, "OPTIONS", [], 1000),
+    ?assertEqual({200, "OK"}, status(Response)),
+    ?assertEqual(<<?DEFAULT_STRING>>, body(Response)).
+
 server_connection_close() ->
     Port = start(gen_tcp, [fun respond_and_close/5]),
     URL = url(Port, "/close"),
         ?DEFAULT_STRING
     ).
 
+head_response(Module, Socket, _Request, _Headers, _Body) ->
+    Module:send(
+        Socket,
+        "HTTP/1.1 200 OK\r\n"
+        "Server: Test server!\r\n\r\n"
+    ).
+
+no_content_response(Module, Socket, _Request, _Headers, _Body) ->
+    Module:send(
+        Socket,
+        "HTTP/1.1 204 OK\r\n"
+        "Server: Test server!\r\n\r\n"
+    ).
+
 empty_body(Module, Socket, _, _, _) ->
     Module:send(
         Socket,