Commits

Oscar Hellström committed 152c8cb Merge

Merged with 1.2 branch

  • Participants
  • Parent commits f8df311, c65d6d4

Comments (0)

Files changed (2)

File src/lhttpc_client.erl

     false;
 has_body("OPTIONS", _, Hdrs) ->
     % OPTIONS can include a body, if Content-Length or Transfer-Encoding
-    % indicates it.
+    % indicates it
     ContentLength = lhttpc_lib:header_value("content-length", Hdrs),
     TransferEncoding = lhttpc_lib:header_value("transfer-encoding", Hdrs),
     case {ContentLength, TransferEncoding} of
         {_, _}                 -> true
     end;
 has_body(_, 204, _) ->
-    false; % 204 No content can't have a body
+    false; % RFC 2616 10.2.5: 204 No Content
+has_body(_, 304, _) ->
+    false; % RFC 2616 10.3.5: 304 Not Modified
 has_body(_, _, _) ->
     true. % All other responses are assumed to have a body
 

File test/lhttpc_tests.erl

                 ?_test(get_with_connect_options()),
                 ?_test(no_content_length()),
                 ?_test(no_content_length_1_0()),
+                ?_test(get_not_modified()),
                 ?_test(simple_head()),
                 ?_test(simple_head_atom()),
                 ?_test(delete_no_content()),
     ?assertEqual({200, "OK"}, status(Response)),
     ?assertEqual(<<?DEFAULT_STRING>>, body(Response)).
 
+get_not_modified() ->
+    Port = start(gen_tcp, [fun not_modified_response/5]),
+    URL = url(Port, "/not_modified"),
+    {ok, Response} = lhttpc:request(URL, "GET", [], [], 1000),
+    ?assertEqual({304, "Not Modified"}, status(Response)),
+    ?assertEqual(<<>>, body(Response)).
+
 simple_head() ->
     Port = start(gen_tcp, [fun head_response/5]),
     URL = url(Port, "/HEAD"),
         "Content-type: text/plain\r\nContent-length: 14\r\n\r\n"
     ),
     Module:close(Socket).
+
+not_modified_response(Module, Socket, _Request, _Headers, _Body) ->
+    Module:send(
+        Socket,
+		[
+			"HTTP/1.1 304 Not Modified\r\n"
+			"Date: Tue, 15 Nov 1994 08:12:31 GMT\r\n\r\n"
+		]
+    ).