From a6f75aa3dcf3de4638d3f454b17bece8ef213bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 11 Jun 2015 17:04:21 +0200 Subject: Add HTTP/2 support preview 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. --- src/cowboy.erl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/cowboy.erl') diff --git a/src/cowboy.erl b/src/cowboy.erl index af9f1b3..1f0e2a9 100644 --- a/src/cowboy.erl +++ b/src/cowboy.erl @@ -17,9 +17,13 @@ -export([start_http/4]). -export([start_https/4]). -export([start_spdy/4]). +-export([start_tls/4]). -export([stop_listener/1]). -export([set_env/3]). +-type opts() :: map(). +-export_type([opts/0]). + -type fields() :: [atom() | {atom(), cowboy_constraints:constraint() | [cowboy_constraints:constraint()]} | {atom(), cowboy_constraints:constraint() | [cowboy_constraints:constraint()], any()}]. @@ -64,6 +68,18 @@ start_spdy(Ref, NbAcceptors, TransOpts, ProtoOpts) ranch:start_listener(Ref, NbAcceptors, ranch_ssl, TransOpts2, cowboy_spdy, ProtoOpts). +-spec start_tls(ranch:ref(), non_neg_integer(), ranch_ssl:opts(), opts()) -> {ok, pid()} | {error, any()}. +start_tls(Ref, NbAcceptors, TransOpts0, ProtoOpts) + when is_integer(NbAcceptors), NbAcceptors > 0 -> + {_, Type} = maps:get(stream_handler, ProtoOpts, {cowboy_stream_h, supervisor}), + TransOpts = [ + {connection_type, Type}, + {next_protocols_advertised, [<<"h2">>, <<"spdy/3">>, <<"http/1.1">>]}, + {alpn_preferred_protocols, [<<"h2">>, <<"spdy/3">>, <<"http/1.1">>]} + |TransOpts0], + ranch:start_listener(Ref, NbAcceptors, + ranch_ssl, TransOpts, cowboy_tls, ProtoOpts). + -spec stop_listener(ranch:ref()) -> ok | {error, not_found}. stop_listener(Ref) -> ranch:stop_listener(Ref). -- cgit v1.2.3