aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_stream.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-06-11 17:04:21 +0200
committerLoïc Hoguin <[email protected]>2015-06-11 17:04:21 +0200
commita6f75aa3dcf3de4638d3f454b17bece8ef213bb9 (patch)
tree2fa8c9cb2545d0c5b79e5c0cdea054c81fcfbb7f /src/cowboy_stream.erl
parent271869889587085494baaedc6b44e939252637f0 (diff)
downloadcowboy-a6f75aa3dcf3de4638d3f454b17bece8ef213bb9.tar.gz
cowboy-a6f75aa3dcf3de4638d3f454b17bece8ef213bb9.tar.bz2
cowboy-a6f75aa3dcf3de4638d3f454b17bece8ef213bb9.zip
Add HTTP/2 support preview2.0.0-pre.2
This commit is not only an early preview of HTTP/2, it is an early preview of the new Cowboy architecture that will be presented tomorrow in my talk. If you have found it before the talk, great! It's not complete so you better go watch the talk anyway.
Diffstat (limited to 'src/cowboy_stream.erl')
-rw-r--r--src/cowboy_stream.erl53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/cowboy_stream.erl b/src/cowboy_stream.erl
new file mode 100644
index 0000000..25ddb1a
--- /dev/null
+++ b/src/cowboy_stream.erl
@@ -0,0 +1,53 @@
+%% Copyright (c) 2015, Loïc Hoguin <[email protected]>
+%%
+%% Permission to use, copy, modify, and/or distribute this software for any
+%% purpose with or without fee is hereby granted, provided that the above
+%% copyright notice and this permission notice appear in all copies.
+%%
+%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+-module(cowboy_stream).
+
+-type streamid() :: any().
+-type fin() :: fin | nofin.
+-type headers() :: map(). %% @todo cowboy:http_headers() when they're maps
+
+-type status_code() :: 100..999. %% @todo cowboy:http_status() when not binary
+-type state() :: any().
+
+-type commands() :: [{response, fin(), status_code(), headers()}
+ | {data, fin(), iodata()}
+ | {promise, binary(), binary(), binary(), binary(), headers()}
+ | {flow, auto | integer()}
+ | {spawn, pid()}
+ | {upgrade, module(), state()}].
+
+-type human_reason() :: atom().
+-type reason() :: [{internal_error, timeout | {error | exit | throw, any()}, human_reason()}
+ | {socket_error, closed | atom(), human_reason()}
+ | {stream_error, cow_http2:error_reason(), human_reason()}
+ | {connection_error, cow_http2:error_reason(), human_reason()}
+ | {stop, cow_http2:frame(), human_reason()}].
+
+-callback init(streamid(), fin(), binary(), binary(), binary(), binary(),
+ headers(), cowboy:opts()) -> {commands(), state()}.
+-callback data(streamid(), fin(), binary(), State) -> {commands(), State} when State::state().
+-callback info(streamid(), any(), state()) -> {commands(), State} when State::state().
+-callback terminate(streamid(), reason(), state()) -> any().
+
+%% @todo To optimize the number of active timers we could have a command
+%% that enables a timeout that is called in the absence of any other call,
+%% similar to what gen_server does. However the nice thing about this is
+%% that the connection process can keep a single timer around (the same
+%% one that would be used to detect half-closed sockets) and use this
+%% timer and other events to trigger the timeout in streams at their
+%% intended time.
+%%
+%% This same timer can be used to try and send PING frames to help detect
+%% that the connection is indeed unresponsive.