aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers/ws_frozen_h.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-08-08 16:33:09 +0200
committerLoïc Hoguin <[email protected]>2019-09-05 11:28:07 +0200
commitc974b4334e7ab660f9bf95653696c3663c02ead3 (patch)
tree9e501a4928b261c4fe9adc74d80c47b6b14ae50a /test/handlers/ws_frozen_h.erl
parent491ddf58c0e14824a741852fdc522b390b306ae2 (diff)
downloadgun-c974b4334e7ab660f9bf95653696c3663c02ead3.tar.gz
gun-c974b4334e7ab660f9bf95653696c3663c02ead3.tar.bz2
gun-c974b4334e7ab660f9bf95653696c3663c02ead3.zip
Implement graceful shutdown
The graceful shutdown is implemented through a new 'closing' state. This state is entered under different circumstances depending on the protocol. The gun:shutdown/1 function is now implemented and documented. It allows shutting down the connection gracefully regardless of the current state of the connection and for all protocols. The behavior is entirely dependent on the protocol. For HTTP/1.1 the connection stays up only until after the current stream is complete; other streams are immediately canceled. For HTTP/2 a GOAWAY frame is sent and existing streams continue to be processed. The connection is closed after all streams are processed and the server's GOAWAY frame is received. For Websocket a close frame is sent. The connection is closed when receiving the server's close frame. In all cases the closing_timeout option defines how long we wait, as a maximum, before closing the connection after the graceful shutdown was started. The graceful shutdown is also initiated when the owner process goes away; when sending an HTTP/1.1 request with the connection: close header; when receiving an HTTP/1.1 response with the connection: close header; when receiving an HTTP/1.0 response without a connection header; when the server sends a GOAWAY HTTP/2 frame; or when we send or receive a Websocket close frame. Along with these changes, the gun:ws_send/2 function now accepts a list of frames as argument. Those frames may include a close frame that initiates the graceful shutdown.
Diffstat (limited to 'test/handlers/ws_frozen_h.erl')
-rw-r--r--test/handlers/ws_frozen_h.erl23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/handlers/ws_frozen_h.erl b/test/handlers/ws_frozen_h.erl
new file mode 100644
index 0000000..bac77c2
--- /dev/null
+++ b/test/handlers/ws_frozen_h.erl
@@ -0,0 +1,23 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(ws_frozen_h).
+
+-export([init/2]).
+-export([websocket_init/1]).
+-export([websocket_handle/2]).
+-export([websocket_info/2]).
+
+init(Req, State) ->
+ {cowboy_websocket, Req, State, #{
+ compress => true
+ }}.
+
+websocket_init(Timeout) ->
+ timer:sleep(Timeout),
+ {ok, undefined}.
+
+websocket_handle(_Frame, State) ->
+ {[], State}.
+
+websocket_info(_Info, State) ->
+ {[], State}.