Skip to content

Commit 4d0e032

Browse files
committed
http_parser: always return {done, binary()} when the parsing is done.
1 parent 6dbdda2 commit 4d0e032

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

NEWS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# NEWS
22

3-
### 0.1.0 - 2013/12/10
3+
0.1.1 - 2013/12/19
4+
------------------
5+
6+
- http_parser: only check body_state=done wheh we are done.
7+
- http_parser: always return `{done, binary()}` when the parsing is
8+
done.
9+
10+
0.1.0 - 2013/12/19
11+
------------------
412

513
- initial release

src/hackney_http.erl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
%%% - `{ok, binary(), parser()}': on body, when a chunk has been
4747
%%% parsed. To continue the parsing you must call
4848
%%% `hackney_http:execute/1' with the given `parser()'.
49-
%%% - `done': when the parsing is done
50-
%%% - `{done, binary()}': on body, when no more need to be parsing. The binary
49+
%%% - `{done, binary()}': when the parsing is done. The binary
5150
%%% given correpond to the non parsed part of the internal buffer.
5251
%%% - `{error, term{}}': when an error happen
5352

@@ -83,8 +82,7 @@
8382
-type uri() :: binary().
8483
-type body_result() :: {more, parser(), binary()}
8584
| {ok, binary(), parser()}
86-
| {done, binary()}
87-
| done.
85+
| {done, binary()}.
8886

8987
-type parser_result() ::
9088
{response, http_version(), status(), http_reason(), parser()}
@@ -328,20 +326,20 @@ parse_trailers(St, Acc) ->
328326
end.
329327

330328
parse_body(St=#hparser{body_state=waiting, te=TE, clen=Length,
331-
method=Method}) ->
329+
method=Method, buffer=Buffer}) ->
332330
case TE of
333331
<<"chunked">> ->
334332
parse_body(St#hparser{body_state=
335333
{stream, fun te_chunked/2, {0, 0}, fun ce_identity/1}});
336334
_ when Length =:= 0 orelse Method =:= <<"HEAD">> ->
337-
done;
335+
{done, Buffer};
338336
_ ->
339337
parse_body(St#hparser{body_state=
340338
{stream, fun te_identity/2, {0, Length},
341339
fun ce_identity/1}})
342340
end;
343-
parse_body(#hparser{body_state=done}) ->
344-
done;
341+
parse_body(#hparser{body_state=done, buffer=Buffer}) ->
342+
{done, Buffer};
345343
parse_body(St=#hparser{buffer=Buffer, body_state={stream, _, _, _}})
346344
when Buffer =/= <<>> ->
347345
transfer_decode(Buffer, St#hparser{buffer= <<>>});
@@ -389,7 +387,7 @@ transfer_decode(Data, St=#hparser{
389387
content_decode(ContentDecode, Data2, St#hparser{buffer=Rest,
390388
body_state=done});
391389
done ->
392-
done;
390+
{done, <<>>};
393391
{error, Reason} ->
394392
{error, Reason}
395393
end.

src/hackney_lib.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{application, hackney_lib,
55
[
66
{description, "Web toolkit"},
7-
{vsn, "0.1.0"},
7+
{vsn, "0.1.1"},
88
{registered, []},
99
{applications, [mimetypes]},
1010
{included_applications, []},

0 commit comments

Comments
 (0)