aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--guide/http.md18
-rw-r--r--src/gun_spdy.erl13
-rw-r--r--test/twitter_SUITE.erl2
3 files changed, 19 insertions, 14 deletions
diff --git a/guide/http.md b/guide/http.md
index a44e95a..2b16f1a 100644
--- a/guide/http.md
+++ b/guide/http.md
@@ -150,11 +150,15 @@ process as a message. First a response message is sent, then
zero or more data messages. If something goes wrong, error
messages are sent instead.
-You can find out whether data will be sent by checking the
-presence of the content-type or content-length header and
-making sure the length isn't 0. If you already know a body is
-going to be sent you can skip this check, however do make
-sure you have a timeout just in case something goes wrong.
+The response message will inform you whether there will be
+data messages following. If it contains `fin` then no data
+will follow. If it contains `nofin` then one or more data
+messages will arrive.
+
+When using SPDY this value is sent along the frame and simply
+passed on in the message. When using HTTP however Gun must
+guess whether data will follow by looking at the headers
+as documented in the HTTP RFC.
``` erlang
StreamRef = gun:get(Pid, "/"),
@@ -162,7 +166,9 @@ receive
{'DOWN', Tag, _, _, Reason} ->
error_logger:error_msg("Oops!"),
exit(Reason);
- {gun_response, Pid, StreamRef, Status, Headers} ->
+ {gun_response, Pid, StreamRef, fin, Status, Headers} ->
+ no_data;
+ {gun_response, Pid, StreamRef, nofin, Status, Headers} ->
receive_data(Pid, StreamRef)
after 1000 ->
exit(timeout)
diff --git a/src/gun_spdy.erl b/src/gun_spdy.erl
index 441532e..db91852 100644
--- a/src/gun_spdy.erl
+++ b/src/gun_spdy.erl
@@ -115,13 +115,12 @@ handle_frame(Rest, State=#spdy_state{owner=Owner,
Transport:send(Socket,
cow_spdy:rst_stream(StreamID, stream_already_closed)),
handle_loop(Rest, delete_stream(StreamID, State));
- S = #stream{ref=StreamRef} ->
- Owner ! {gun_response, self(), StreamRef, Status, Headers},
- if IsFin ->
- handle_loop(Rest, in_fin_stream(S, State));
- true ->
- handle_loop(Rest, State)
- end;
+ S = #stream{ref=StreamRef} when IsFin ->
+ Owner ! {gun_response, self(), StreamRef, fin, Status, Headers},
+ handle_loop(Rest, in_fin_stream(S, State));
+ #stream{ref=StreamRef} ->
+ Owner ! {gun_response, self(), StreamRef, nofin, Status, Headers},
+ handle_loop(Rest, State);
false ->
Transport:send(Socket,
cow_spdy:rst_stream(StreamID, invalid_stream)),
diff --git a/test/twitter_SUITE.erl b/test/twitter_SUITE.erl
index ad698a3..b547ed5 100644
--- a/test/twitter_SUITE.erl
+++ b/test/twitter_SUITE.erl
@@ -51,7 +51,7 @@ spdy(_) ->
{ok, Pid} = gun:open("twitter.com", 443),
Ref = gun:get(Pid, "/"),
receive
- {gun_response, Pid, Ref, Status, Headers} ->
+ {gun_response, Pid, Ref, nofin, Status, Headers} ->
ct:print("response ~p ~p", [Status, Headers]),
data_loop(Pid, Ref)
after 5000 ->