Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set body of 304 responses to 0 bytes

Some servers do not send a Content-Length header when replying with a "304
Not Modified" response in a persistent connection. According to rfc2616,
304 responses must not have a body, so set the content to an empty binary.
  • Loading branch information...
commit 205d9424d207efedb5a1950774abf9c97929a889 1 parent a56fb0b
@msantos authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/pervon.erl
View
13 src/pervon.erl
@@ -237,18 +237,29 @@ dump(#state{
content(_Path, _Name, <<>>) ->
ok;
content(Path, Name, Payload) ->
- {ok, {_Version, _Code, _Response, Headers, Body}} = httpc_response:parse([Payload, ?MAXHDRLEN, true]),
+ {ok, {_Version, Code, _Response, Headers, Body}} = httpc_response:parse([Payload, ?MAXHDRLEN, true]),
{Hdr, Content, Rest} = case {Headers#http_response_h.'transfer-encoding',
Headers#http_response_h.'content-length'} of
+
{"chunked", "-1"} ->
{ok, {ChunkHdr, Chunk}} = http_chunk:decode(Body, ?MAXCHUNKLEN, ?MAXHDRLEN),
Headers1 = http_chunk:handle_headers(Headers, ChunkHdr),
N = list_to_integer(Headers1#http_response_h.'content-length'),
<<B1:N/bytes, B2/binary>> = Chunk,
{Headers1, B1, B2};
+
+ % Some servers do not send a Content-Length header when replying with a
+ % "304 Not Modified" response in a persistent connection. 304 responses
+ % cannot have a body (see RFC 2616).
+ {_, "-1"} when Code =:= 304 ->
+ {Headers, <<>>, Body};
+
+ % No Content-Length header; the end of response is indicated by closing
+ % the socket
{_, "-1"} ->
{Headers, Body, <<>>};
+
{_, Size} ->
N = list_to_integer(Size),
<<B1:N/bytes, B2/binary>> = Body,
Please sign in to comment.
Something went wrong with that request. Please try again.