Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Further simplify content parsing

Use Content-Length set in the outer scope.
  • Loading branch information...
commit bc666dff6d4237e88e6cca477bc08bf4e663db0a 1 parent 205d942
@msantos authored
Showing with 5 additions and 6 deletions.
  1. +5 −6 src/pervon.erl
View
11 src/pervon.erl
@@ -239,10 +239,9 @@ content(_Path, _Name, <<>>) ->
content(Path, Name, Payload) ->
{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
+ {Hdr, Content, Rest} = case Headers#http_response_h.'content-length' of
- {"chunked", "-1"} ->
+ "-1" when Headers#http_response_h.'transfer-encoding' == "chunked" ->
{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'),
@@ -252,15 +251,15 @@ content(Path, Name, Payload) ->
% 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 ->
+ "-1" when Code =:= 304 ->
{Headers, <<>>, Body};
% No Content-Length header; the end of response is indicated by closing
% the socket
- {_, "-1"} ->
+ "-1" ->
{Headers, Body, <<>>};
- {_, Size} ->
+ Size ->
N = list_to_integer(Size),
<<B1:N/bytes, B2/binary>> = Body,
{Headers, B1, B2}
Please sign in to comment.
Something went wrong with that request. Please try again.