0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 04:30:25 +00:00

Add cowboy_protocol:opts() type

Should improve the detection of wrong protocol options.
This commit is contained in:
Loïc Hoguin 2013-05-16 17:56:45 +02:00
parent 2e787fed56
commit 6d1344319a
2 changed files with 20 additions and 4 deletions

View file

@ -37,14 +37,16 @@
-export_type([onresponse_fun/0]). -export_type([onresponse_fun/0]).
%% @doc Start an HTTP listener. %% @doc Start an HTTP listener.
-spec start_http(any(), non_neg_integer(), any(), any()) -> {ok, pid()}. -spec start_http(any(), non_neg_integer(), any(),
cowboy_protocol:opts()) -> {ok, pid()}.
start_http(Ref, NbAcceptors, TransOpts, ProtoOpts) start_http(Ref, NbAcceptors, TransOpts, ProtoOpts)
when is_integer(NbAcceptors), NbAcceptors > 0 -> when is_integer(NbAcceptors), NbAcceptors > 0 ->
ranch:start_listener(Ref, NbAcceptors, ranch:start_listener(Ref, NbAcceptors,
ranch_tcp, TransOpts, cowboy_protocol, ProtoOpts). ranch_tcp, TransOpts, cowboy_protocol, ProtoOpts).
%% @doc Start an HTTPS listener. %% @doc Start an HTTPS listener.
-spec start_https(any(), non_neg_integer(), any(), any()) -> {ok, pid()}. -spec start_https(any(), non_neg_integer(), any(),
cowboy_protocol:opts()) -> {ok, pid()}.
start_https(Ref, NbAcceptors, TransOpts, ProtoOpts) start_https(Ref, NbAcceptors, TransOpts, ProtoOpts)
when is_integer(NbAcceptors), NbAcceptors > 0 -> when is_integer(NbAcceptors), NbAcceptors > 0 ->
ranch:start_listener(Ref, NbAcceptors, ranch:start_listener(Ref, NbAcceptors,

View file

@ -56,6 +56,20 @@
-export([parse_request/3]). -export([parse_request/3]).
-export([resume/6]). -export([resume/6]).
-type opts() :: [{compress, boolean()}
| {env, cowboy_middleware:env()}
| {max_empty_lines, non_neg_integer()}
| {max_header_name_length, non_neg_integer()}
| {max_header_value_length, non_neg_integer()}
| {max_headers, non_neg_integer()}
| {max_keepalive, non_neg_integer()}
| {max_request_line_length, non_neg_integer()}
| {middlewares, [module()]}
| {onrequest, cowboy:onrequest_fun()}
| {onresponse, cowboy:onresponse_fun()}
| {timeout, timeout()}].
-export_type([opts/0]).
-record(state, { -record(state, {
socket :: inet:socket(), socket :: inet:socket(),
transport :: module(), transport :: module(),
@ -78,7 +92,7 @@
%% API. %% API.
%% @doc Start an HTTP protocol process. %% @doc Start an HTTP protocol process.
-spec start_link(any(), inet:socket(), module(), any()) -> {ok, pid()}. -spec start_link(any(), inet:socket(), module(), opts()) -> {ok, pid()}.
start_link(Ref, Socket, Transport, Opts) -> start_link(Ref, Socket, Transport, Opts) ->
Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]), Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
{ok, Pid}. {ok, Pid}.
@ -94,7 +108,7 @@ get_value(Key, Opts, Default) ->
end. end.
%% @private %% @private
-spec init(any(), inet:socket(), module(), any()) -> ok. -spec init(any(), inet:socket(), module(), opts()) -> ok.
init(Ref, Socket, Transport, Opts) -> init(Ref, Socket, Transport, Opts) ->
Compress = get_value(compress, Opts, false), Compress = get_value(compress, Opts, false),
MaxEmptyLines = get_value(max_empty_lines, Opts, 5), MaxEmptyLines = get_value(max_empty_lines, Opts, 5),