Skip to content

Commit

Permalink
Revert "Add preliminary support for trailers"
Browse files Browse the repository at this point in the history
This reverts commit cbbb4d5.
  • Loading branch information
Steve Cohen committed Dec 19, 2017
1 parent b297499 commit da4fb20
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 52 deletions.
6 changes: 0 additions & 6 deletions src/gun.erl
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ await(ServerPid, StreamRef, Timeout, MRef) ->
{response, IsFin, Status, Headers};
{gun_data, ServerPid, StreamRef, IsFin, Data} ->
{data, IsFin, Data};
{gun_trailers, ServerPid, StreamRef, Trailers} ->
{trailers, Trailers};
{gun_push, ServerPid, StreamRef, NewStreamRef, Method, URI, Headers} ->
{push, NewStreamRef, Method, URI, Headers};
{gun_error, ServerPid, StreamRef, Reason} ->
Expand Down Expand Up @@ -406,10 +404,6 @@ await_body(ServerPid, StreamRef, Timeout, MRef, Acc) ->
<< Acc/binary, Data/binary >>);
{gun_data, ServerPid, StreamRef, fin, Data} ->
{ok, << Acc/binary, Data/binary >>};
%% It's OK to return trailers here because the client
%% specifically requested them.
{gun_trailers, ServerPid, StreamRef, Trailers} ->
{ok, Acc, Trailers};
{gun_error, ServerPid, StreamRef, Reason} ->
{error, Reason};
{gun_error, ServerPid, Reason} ->
Expand Down
47 changes: 9 additions & 38 deletions src/gun_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
-export([down/1]).
-export([ws_upgrade/7]).

-type io() :: head | {body, non_neg_integer()} | body_close | body_chunked | body_trailer.
-type io() :: head | {body, non_neg_integer()} | body_close | body_chunked.

%% @todo Make that a record.
-type websocket_info() :: {websocket, reference(), binary(), [binary()], gun:ws_opts()}. %% key, extensions, options
Expand Down Expand Up @@ -101,7 +101,6 @@ handle(Data, State=#http_state{in=head, buffer=Buffer}) ->
%% Everything sent to the socket until it closes is part of the response body.
handle(Data, State=#http_state{in=body_close}) ->
send_data_if_alive(Data, State, nofin);
%% Chunked transfer-encoding may contain both data and trailers.
handle(Data, State=#http_state{in=body_chunked, in_state=InState,
buffer=Buffer, connection=Conn}) ->
Buffer2 = << Buffer/binary, Data/binary >>,
Expand All @@ -122,48 +121,20 @@ handle(Data, State=#http_state{in=body_chunked, in_state=InState,
send_data_if_alive(Data2,
State#http_state{buffer=Rest, in_state=InState2},
nofin);
{done, HasTrailers, Rest} ->
IsFin = case HasTrailers of
trailers -> nofin;
no_trailers -> fin
end,
{done, _TotalLength, Rest} ->
%% I suppose it doesn't hurt to append an empty binary.
State1 = send_data_if_alive(<<>>, State, IsFin),
case {HasTrailers, Conn} of
{trailers, _} ->
handle(Rest, State1#http_state{buffer = <<>>, in=body_trailer});
{no_trailers, keepalive} ->
State1 = send_data_if_alive(<<>>, State, fin),
case Conn of
keepalive ->
handle(Rest, end_stream(State1#http_state{buffer= <<>>}));
{no_trailers, close} ->
close ->
close
end;
{done, Data2, HasTrailers, Rest} ->
IsFin = case HasTrailers of
trailers -> nofin;
no_trailers -> fin
end,
State1 = send_data_if_alive(Data2, State, IsFin),
case {HasTrailers, Conn} of
{trailers, _} ->
handle(Rest, State1#http_state{buffer = <<>>, in=body_trailer});
{no_trailers, keepalive} ->
handle(Rest, end_stream(State1#http_state{buffer= <<>>}));
{no_trailers, close} ->
close
end
end;
handle(Data, State=#http_state{in=body_trailer, buffer=Buffer, connection=Conn,
streams=[#stream{ref=StreamRef, reply_to=ReplyTo}|_]}) ->
Data2 = << Buffer/binary, Data/binary >>,
case binary:match(Data2, <<"\r\n\r\n">>) of
nomatch -> State#http_state{buffer=Data2};
{_, _} ->
{Trailers, Rest} = cow_http:parse_headers(Data2),
%% @todo We probably want to pass this to gun_content_handler?
ReplyTo ! {gun_trailers, self(), stream_ref(StreamRef), Trailers},
{done, Data2, _TotalLength, Rest} ->
State1 = send_data_if_alive(Data2, State, fin),
case Conn of
keepalive ->
handle(Rest, end_stream(State#http_state{buffer= <<>>}));
handle(Rest, end_stream(State1#http_state{buffer= <<>>}));
close ->
close
end
Expand Down
10 changes: 2 additions & 8 deletions src/gun_http2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,9 @@ frame({headers, StreamID, IsFin, head_fin, HeaderBlock},
remote_fin(Stream#stream{handler_state=Handlers},
State#http2_state{decode_state=DecodeState}, IsFin)
end;
%% @todo For now we assume that it's a trailer if there's no :status.
%% A better state machine is needed to distinguish between that and errors.
false ->
%% @todo We probably want to pass this to gun_content_handler?
ReplyTo ! {gun_trailers, self(), StreamRef, Headers0},
remote_fin(Stream, State#http2_state{decode_state=DecodeState}, fin)
%% false ->
%% stream_reset(State, StreamID, {stream_error, protocol_error,
%% 'Malformed response; missing :status in HEADERS frame. (RFC7540 8.1.2.4)'})
stream_reset(State, StreamID, {stream_error, protocol_error,
'Malformed response; missing :status in HEADERS frame. (RFC7540 8.1.2.4)'})
end
catch _:_ ->
terminate(State, StreamID, {connection_error, compression_error,
Expand Down

0 comments on commit da4fb20

Please sign in to comment.