From 3d1e3c9e6e779bca839b86717adb2487b4a1c2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 24 Jul 2019 16:22:26 +0200 Subject: Add the cancel event for local/remote stream cancellation --- src/gun_http.erl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/gun_http.erl') diff --git a/src/gun_http.erl b/src/gun_http.erl index da72527..738b6e9 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -24,7 +24,7 @@ -export([request/11]). -export([data/7]). -export([connect/5]). --export([cancel/3]). +-export([cancel/5]). -export([stream_info/2]). -export([down/1]). -export([ws_upgrade/9]). @@ -605,12 +605,19 @@ connect(State=#http_state{socket=Socket, transport=Transport, version=Version}, new_stream(State, {connect, StreamRef, Destination}, ReplyTo, <<"CONNECT">>). %% We can't cancel anything, we can just stop forwarding messages to the owner. -cancel(State, StreamRef, ReplyTo) -> - case is_stream(State, StreamRef) of +cancel(State0, StreamRef, ReplyTo, EvHandler, EvHandlerState0) -> + case is_stream(State0, StreamRef) of true -> - cancel_stream(State, StreamRef); + State = cancel_stream(State0, StreamRef), + EvHandlerState = EvHandler:cancel(#{ + stream_ref => StreamRef, + reply_to => ReplyTo, + endpoint => local, + reason => cancel + }, EvHandlerState0), + {State, EvHandlerState}; false -> - error_stream_not_found(State, StreamRef, ReplyTo) + {error_stream_not_found(State0, StreamRef, ReplyTo), EvHandlerState0} end. stream_info(#http_state{streams=Streams}, StreamRef) -> -- cgit v1.2.3