diff options
author | Loïc Hoguin <[email protected]> | 2017-01-16 14:22:43 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-01-16 14:36:33 +0100 |
commit | 0f8452cafaa27aeffb103019564c086eacfd34f9 (patch) | |
tree | 6f060f0c7e1eb54508cd128c9bf281869593e812 /src/cowboy.erl | |
parent | e5a8088e68f29206e162ee0f25f45a55ce05fe04 (diff) | |
download | cowboy-0f8452cafaa27aeffb103019564c086eacfd34f9.tar.gz cowboy-0f8452cafaa27aeffb103019564c086eacfd34f9.tar.bz2 cowboy-0f8452cafaa27aeffb103019564c086eacfd34f9.zip |
Add support for multiple stream handlers
The stream handlers can be specified using the protocol
option 'stream_handlers'. It defaults to [cowboy_stream_h].
The cowboy_stream_h module currently does not forward the
calls to further stream handlers. It feels like an edge
case; usually we'd want to put our own handlers between
the protocol code and the request process. I am therefore
going to focus on other things for now.
The various types and specifications for stream handlers
have been updated and the cowboy_stream module can now
be safely used as a behavior. The interface might change
a little more, though.
This commit does not include tests or documentation.
They will follow separately.
Diffstat (limited to 'src/cowboy.erl')
-rw-r--r-- | src/cowboy.erl | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/cowboy.erl b/src/cowboy.erl index 7bb9f1f..56aef34 100644 --- a/src/cowboy.erl +++ b/src/cowboy.erl @@ -41,26 +41,29 @@ %% doesn't let us do that yet. -spec start_clear(ranch:ref(), non_neg_integer(), ranch_tcp:opts(), opts()) -> {ok, pid()} | {error, any()}. -start_clear(Ref, NbAcceptors, TransOpts0, ProtoOpts) +start_clear(Ref, NbAcceptors, TransOpts0, ProtoOpts0) when is_integer(NbAcceptors), NbAcceptors > 0 -> - TransOpts = [connection_type(ProtoOpts)|TransOpts0], + {TransOpts, ConnectionType} = ensure_connection_type(TransOpts0), + ProtoOpts = ProtoOpts0#{connection_type => ConnectionType}, ranch:start_listener(Ref, NbAcceptors, ranch_tcp, TransOpts, cowboy_clear, ProtoOpts). -spec start_tls(ranch:ref(), non_neg_integer(), ranch_ssl:opts(), opts()) -> {ok, pid()} | {error, any()}. -start_tls(Ref, NbAcceptors, TransOpts0, ProtoOpts) +start_tls(Ref, NbAcceptors, TransOpts0, ProtoOpts0) when is_integer(NbAcceptors), NbAcceptors > 0 -> + {TransOpts1, ConnectionType} = ensure_connection_type(TransOpts0), TransOpts = [ - connection_type(ProtoOpts), {next_protocols_advertised, [<<"h2">>, <<"http/1.1">>]}, {alpn_preferred_protocols, [<<"h2">>, <<"http/1.1">>]} - |TransOpts0], + |TransOpts1], + ProtoOpts = ProtoOpts0#{connection_type => ConnectionType}, ranch:start_listener(Ref, NbAcceptors, ranch_ssl, TransOpts, cowboy_tls, ProtoOpts). --spec connection_type(opts()) -> {connection_type, worker | supervisor}. -connection_type(ProtoOpts) -> - {_, Type} = maps:get(stream_handler, ProtoOpts, {cowboy_stream_h, supervisor}), - {connection_type, Type}. +ensure_connection_type(TransOpts) -> + case proplists:get_value(connection_type, TransOpts) of + undefined -> {[{connection_type, supervisor}|TransOpts], supervisor}; + ConnectionType -> {TransOpts, ConnectionType} + end. -spec stop_listener(ranch:ref()) -> ok | {error, not_found}. stop_listener(Ref) -> |