From b09b19b5bbb0f1188b64083bc4092d8f65c375e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Hellstr=C3=B6m?= Date: Thu, 11 Feb 2010 08:37:10 +0000 Subject: [PATCH 1/2] Add test for 304 "Not Modified" --HG-- branch : 1.2 --- test/lhttpc_tests.erl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/lhttpc_tests.erl b/test/lhttpc_tests.erl index 36bbe057..a7f6ff22 100644 --- a/test/lhttpc_tests.erl +++ b/test/lhttpc_tests.erl @@ -53,6 +53,7 @@ tcp_test_() -> ?_test(get_with_mandatory_hdrs()), ?_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()), @@ -131,6 +132,13 @@ no_content_length_1_0() -> ?assertEqual({200, "OK"}, status(Response)), ?assertEqual(<>, 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"), @@ -550,3 +558,12 @@ close_connection(Module, Socket, _, _, _) -> "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" + ] + ). From 2bba718d232957d684544453792367dcf8409cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Hellstr=C3=B6m?= Date: Thu, 11 Feb 2010 08:40:19 +0000 Subject: [PATCH 2/2] Add fix for 304 Not Modified --HG-- branch : 1.2 --- src/lhttpc_client.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lhttpc_client.erl b/src/lhttpc_client.erl index 053ade36..a6508e7f 100644 --- a/src/lhttpc_client.erl +++ b/src/lhttpc_client.erl @@ -223,7 +223,8 @@ maybe_read_body("OPTIONS", _, Vsn, Hdrs, Ssl, Socket) -> maybe_read_body(_, StatusCode, Vsn, Hdrs, Ssl, Socket) -> % All other requests should have a body, unless indicated otherwise case StatusCode of - 204 -> {<<>>, Hdrs}; + 204 -> {<<>>, Hdrs}; % RFC 2616 10.2.5 + 304 -> {<<>>, Hdrs}; % RFC 2616 10.3.5 _ -> read_body(Vsn, Hdrs, Ssl, Socket) end.