aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-29 21:08:12 +0000
committerLoïc Hoguin <[email protected]>2017-10-29 21:08:12 +0000
commit438239358908090bdf05ecdeb4c7dbaf089a00df (patch)
treea2d0ffd4e254d54d0473542251233472983be05b /src
parentb33e53d64b2a15d7f4e9c4445ee62ab354aabaae (diff)
downloadgun-438239358908090bdf05ecdeb4c7dbaf089a00df.tar.gz
gun-438239358908090bdf05ecdeb4c7dbaf089a00df.tar.bz2
gun-438239358908090bdf05ecdeb4c7dbaf089a00df.zip
Add support for informational responses
Diffstat (limited to 'src')
-rw-r--r--src/gun.erl2
-rw-r--r--src/gun_http.erl12
-rw-r--r--src/gun_http2.erl25
3 files changed, 25 insertions, 14 deletions
diff --git a/src/gun.erl b/src/gun.erl
index 53a6c15..311e405 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -353,6 +353,8 @@ await(ServerPid, StreamRef, Timeout) ->
await(ServerPid, StreamRef, Timeout, MRef) ->
receive
+ {gun_inform, ServerPid, StreamRef, Status, Headers} ->
+ {inform, Status, Headers};
{gun_response, ServerPid, StreamRef, IsFin, Status, Headers} ->
{response, IsFin, Status, Headers};
{gun_data, ServerPid, StreamRef, IsFin, Data} ->
diff --git a/src/gun_http.erl b/src/gun_http.erl
index 204ce4a..3837bb3 100644
--- a/src/gun_http.erl
+++ b/src/gun_http.erl
@@ -174,6 +174,9 @@ handle_head(Data, State=#http_state{version=ClientVersion,
case {Status, StreamRef} of
{101, {websocket, _, WsKey, WsExtensions, WsOpts}} ->
ws_handshake(Rest2, State, Headers, WsKey, WsExtensions, WsOpts);
+ {_, _} when Status >= 100, Status =< 199 ->
+ ReplyTo ! {gun_inform, self(), stream_ref(StreamRef), Status, Headers},
+ handle(Rest2, State);
_ ->
In = response_io_from_headers(Method, Version, Status, Headers),
IsFin = case In of head -> fin; _ -> nofin end,
@@ -181,11 +184,7 @@ handle_head(Data, State=#http_state{version=ClientVersion,
false ->
ok;
true ->
- StreamRef2 = case StreamRef of
- {websocket, SR, _, _, _} -> SR;
- _ -> StreamRef
- end,
- ReplyTo ! {gun_response, self(), StreamRef2,
+ ReplyTo ! {gun_response, self(), stream_ref(StreamRef),
IsFin, Status, Headers},
case IsFin of
fin -> undefined;
@@ -215,6 +214,9 @@ handle_head(Data, State=#http_state{version=ClientVersion,
end
end.
+stream_ref({websocket, StreamRef, _, _, _}) -> StreamRef;
+stream_ref(StreamRef) -> StreamRef.
+
send_data_if_alive(<<>>, State, nofin) ->
State;
%% @todo What if we receive data when the HEAD method was used?
diff --git a/src/gun_http2.erl b/src/gun_http2.erl
index 41ffc2d..decc206 100644
--- a/src/gun_http2.erl
+++ b/src/gun_http2.erl
@@ -144,15 +144,22 @@ frame({headers, StreamID, IsFin, head_fin, HeaderBlock},
{Headers0, DecodeState} ->
case lists:keytake(<<":status">>, 1, Headers0) of
{value, {_, Status}, Headers} ->
- ReplyTo ! {gun_response, self(), StreamRef, IsFin, parse_status(Status), Headers},
- Handlers = case IsFin of
- fin -> undefined;
- nofin ->
- gun_content_handler:init(ReplyTo, StreamRef,
- Status, Headers, Handlers0)
- end,
- remote_fin(Stream#stream{handler_state=Handlers},
- State#http2_state{decode_state=DecodeState}, IsFin);
+ IntStatus = parse_status(Status),
+ if
+ IntStatus >= 100, IntStatus =< 199 ->
+ ReplyTo ! {gun_inform, self(), StreamRef, IntStatus, Headers},
+ State#http2_state{decode_state=DecodeState};
+ true ->
+ ReplyTo ! {gun_response, self(), StreamRef, IsFin, parse_status(Status), Headers},
+ Handlers = case IsFin of
+ fin -> undefined;
+ nofin ->
+ gun_content_handler:init(ReplyTo, StreamRef,
+ Status, Headers, Handlers0)
+ end,
+ remote_fin(Stream#stream{handler_state=Handlers},
+ State#http2_state{decode_state=DecodeState}, IsFin)
+ end;
false ->
stream_reset(State, StreamID, {stream_error, protocol_error,
'Malformed response; missing :status in HEADERS frame. (RFC7540 8.1.2.4)'})