aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_http.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-04-09 23:13:57 +0300
committerLoïc Hoguin <[email protected]>2015-04-09 23:13:57 +0300
commita738db07c2040461f0fd431f04ecf90b157ead5b (patch)
tree3435489b45067c80fc7b7620cf02622676811c24 /src/gun_http.erl
parent2badb594bdedfd1283306fe2075c2c51abdd600d (diff)
downloadgun-a738db07c2040461f0fd431f04ecf90b157ead5b.tar.gz
gun-a738db07c2040461f0fd431f04ecf90b157ead5b.tar.bz2
gun-a738db07c2040461f0fd431f04ecf90b157ead5b.zip
Add gun_up and gun_down messages
The flush(Pid) function was enhanced to also discard Websocket messages and the new up/down messages.
Diffstat (limited to 'src/gun_http.erl')
-rw-r--r--src/gun_http.erl12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl
index 8b176fe..d6a69d1 100644
--- a/src/gun_http.erl
+++ b/src/gun_http.erl
@@ -15,6 +15,7 @@
-module(gun_http).
-export([check_options/1]).
+-export([name/0]).
-export([init/4]).
-export([handle/2]).
-export([close/1]).
@@ -23,6 +24,7 @@
-export([request/8]).
-export([data/4]).
-export([cancel/2]).
+-export([down/1]).
-export([ws_upgrade/7]).
-type io() :: head | {body, non_neg_integer()} | body_close | body_chunked.
@@ -52,6 +54,8 @@ do_check_options([{version, V}|Opts]) when V =:= 'HTTP/1.1'; V =:= 'HTTP/1.0' ->
do_check_options([Opt|_]) ->
{error, {options, {http, Opt}}}.
+name() -> http.
+
init(Owner, Socket, Transport, Opts) ->
Version = maps:get(version, Opts, 'HTTP/1.1'),
#http_state{owner=Owner, socket=Socket, transport=Transport, version=Version}.
@@ -286,6 +290,14 @@ cancel(State, StreamRef) ->
error_stream_not_found(State)
end.
+%% HTTP does not provide any way to figure out what streams are unprocessed.
+down(#http_state{streams=Streams}) ->
+ KilledStreams = [case Ref of
+ {websocket, Ref2, _, _, _} -> Ref2;
+ _ -> Ref
+ end || {Ref, _} <- Streams],
+ {KilledStreams, []}.
+
error_stream_closed(State=#http_state{owner=Owner}) ->
Owner ! {gun_error, self(), {badstate,
"The stream has already been closed."}},