Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merged with 1.2 branch

  • Loading branch information...
commit c0f48bbf54ac29660c4fd15edb6a909dc358cf6f 2 parents 2f548d3 + 2bba718
@oscarh oscarh authored
Showing with 21 additions and 2 deletions.
  1. +4 −2 src/lhttpc_client.erl
  2. +17 −0 test/lhttpc_tests.erl
View
6 src/lhttpc_client.erl
@@ -321,7 +321,7 @@ has_body("HEAD", _, _) ->
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
@@ -329,7 +329,9 @@ has_body("OPTIONS", _, Hdrs) ->
{_, _} -> 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
View
17 test/lhttpc_tests.erl
@@ -117,6 +117,7 @@ tcp_test_() ->
?_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()),
@@ -221,6 +222,13 @@ no_content_length_1_0() ->
?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"),
@@ -963,3 +971,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"
+ ]
+ ).
Please sign in to comment.
Something went wrong with that request. Please try again.