Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Merged with 1.2 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarh committed Feb 11, 2010
2 parents 2f548d3 + 2bba718 commit c0f48bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lhttpc_client.erl
Expand Up @@ -321,15 +321,17 @@ 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
{undefined, undefined} -> false;
{_, _} -> 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

Expand Down
17 changes: 17 additions & 0 deletions test/lhttpc_tests.erl
Expand Up @@ -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()),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"
]
).

0 comments on commit c0f48bb

Please sign in to comment.