diff options
author | Loïc Hoguin <[email protected]> | 2018-10-31 11:45:04 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-10-31 14:11:45 +0100 |
commit | 473e3fb82bd56a984dcf8936a51e3fd8affcb8f4 (patch) | |
tree | c9f126c7117f271b4aa8c739bb5178b9671c9d10 /src | |
parent | a8335c63df31f21d88e9d7d1f2b64d32a674cd7a (diff) | |
download | cowboy-473e3fb82bd56a984dcf8936a51e3fd8affcb8f4.tar.gz cowboy-473e3fb82bd56a984dcf8936a51e3fd8affcb8f4.tar.bz2 cowboy-473e3fb82bd56a984dcf8936a51e3fd8affcb8f4.zip |
Improve a few types, including cowboy_req:req()
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy.erl | 3 | ||||
-rw-r--r-- | src/cowboy_http.erl | 10 | ||||
-rw-r--r-- | src/cowboy_http2.erl | 12 | ||||
-rw-r--r-- | src/cowboy_metrics_h.erl | 3 | ||||
-rw-r--r-- | src/cowboy_req.erl | 65 | ||||
-rw-r--r-- | src/cowboy_tracer_h.erl | 3 |
6 files changed, 61 insertions, 35 deletions
diff --git a/src/cowboy.erl b/src/cowboy.erl index a046199..c4be25b 100644 --- a/src/cowboy.erl +++ b/src/cowboy.erl @@ -23,8 +23,7 @@ -export([log/2]). -export([log/4]). -%% @todo Detailed opts. --type opts() :: map(). +-type opts() :: cowboy_http:opts() | cowboy_http2:opts(). -export_type([opts/0]). -type fields() :: [atom() diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index a6da5c6..fff4e5b 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -39,10 +39,14 @@ max_keepalive => non_neg_integer(), max_method_length => non_neg_integer(), max_request_line_length => non_neg_integer(), + metrics_callback => cowboy_metrics_h:metrics_callback(), middlewares => [module()], + proxy_header => boolean(), request_timeout => timeout(), shutdown_timeout => timeout(), - stream_handlers => [module()] + stream_handlers => [module()], + tracer_callback => cowboy_tracer_h:tracer_callback(), + tracer_match_specs => cowboy_tracer_h:tracer_match_specs() }. -export_type([opts/0]). @@ -56,7 +60,7 @@ path = undefined :: binary(), qs = undefined :: binary(), version = undefined :: cowboy:http_version(), - headers = undefined :: map() | undefined, %% @todo better type than map() + headers = undefined :: cowboy:http_headers() | undefined, name = undefined :: binary() | undefined }). @@ -99,7 +103,7 @@ socket :: inet:socket(), transport :: module(), proxy_header :: undefined | ranch_proxy_header:proxy_info(), - opts = #{} :: map(), + opts = #{} :: cowboy:opts(), %% Remote address and port for the connection. peer = undefined :: {inet:ip_address(), inet:port_number()}, diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl index 6ec7583..f6f9cf5 100644 --- a/src/cowboy_http2.erl +++ b/src/cowboy_http2.erl @@ -39,11 +39,15 @@ max_encode_table_size => non_neg_integer(), max_frame_size_received => 16384..16777215, max_frame_size_sent => 16384..16777215 | infinity, + metrics_callback => cowboy_metrics_h:metrics_callback(), middlewares => [module()], preface_timeout => timeout(), + proxy_header => boolean(), settings_timeout => timeout(), shutdown_timeout => timeout(), - stream_handlers => [module()] + stream_handlers => [module()], + tracer_callback => cowboy_tracer_h:tracer_callback(), + tracer_match_specs => cowboy_tracer_h:tracer_match_specs() }. -export_type([opts/0]). @@ -78,7 +82,7 @@ }). -spec init(pid(), ranch:ref(), inet:socket(), module(), - ranch_proxy_header:proxy_info(), cowboy:opts()) -> ok. + ranch_proxy_header:proxy_info() | undefined, cowboy:opts()) -> ok. init(Parent, Ref, Socket, Transport, ProxyHeader, Opts) -> Peer0 = Transport:peername(Socket), Sock0 = Transport:sockname(Socket), @@ -108,7 +112,7 @@ init(Parent, Ref, Socket, Transport, ProxyHeader, Opts) -> end. -spec init(pid(), ranch:ref(), inet:socket(), module(), - ranch_proxy_header:proxy_info(), cowboy:opts(), + ranch_proxy_header:proxy_info() | undefined, cowboy:opts(), {inet:ip_address(), inet:port_number()}, {inet:ip_address(), inet:port_number()}, binary() | undefined, binary()) -> ok. init(Parent, Ref, Socket, Transport, ProxyHeader, Opts, Peer, Sock, Cert, Buffer) -> @@ -125,7 +129,7 @@ init(Parent, Ref, Socket, Transport, ProxyHeader, Opts, Peer, Sock, Cert, Buffer %% @todo Add an argument for the request body. -spec init(pid(), ranch:ref(), inet:socket(), module(), - ranch_proxy_header:proxy_info(), cowboy:opts(), + ranch_proxy_header:proxy_info() | undefined, cowboy:opts(), {inet:ip_address(), inet:port_number()}, {inet:ip_address(), inet:port_number()}, binary() | undefined, binary(), map() | undefined, cowboy_req:req()) -> ok. init(Parent, Ref, Socket, Transport, ProxyHeader, Opts, Peer, Sock, Cert, Buffer, diff --git a/src/cowboy_metrics_h.erl b/src/cowboy_metrics_h.erl index 559952b..3a2a8f0 100644 --- a/src/cowboy_metrics_h.erl +++ b/src/cowboy_metrics_h.erl @@ -106,6 +106,9 @@ }. -export_type([metrics/0]). +-type metrics_callback() :: fun((metrics()) -> any()). +-export_type([metrics_callback/0]). + -record(state, { next :: any(), callback :: fun((metrics()) -> any()), diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl index dad923f..54f2613 100644 --- a/src/cowboy_req.erl +++ b/src/cowboy_req.erl @@ -121,32 +121,45 @@ }. -export_type([push_opts/0]). --type req() :: map(). %% @todo #{ -% ref := ranch:ref(), -% pid := pid(), -% streamid := cowboy_stream:streamid(), -% peer := {inet:ip_address(), inet:port_number()}, -% proxy_header => ... -% -% method := binary(), %% case sensitive -% version := cowboy:http_version() | atom(), -% scheme := binary(), %% <<"http">> or <<"https">> -% host := binary(), %% lowercase; case insensitive -% port := inet:port_number(), -% path := binary(), %% case sensitive -% qs := binary(), %% case sensitive -% headers := cowboy:http_headers(), -% -% host_info => cowboy_router:tokens(), -% path_info => cowboy_router:tokens(), -% bindings => cowboy_router:bindings(), -% -% has_body := boolean(), -% has_read_body => true, -% body_length := undefined | non_neg_integer() -% -%% @todo resp_* -%}. +-type req() :: #{ + %% Public interface. + method := binary(), + version := cowboy:http_version() | atom(), + scheme := binary(), + host := binary(), + port := inet:port_number(), + path := binary(), + qs := binary(), + headers := cowboy:http_headers(), + peer := {inet:ip_address(), inet:port_number()}, + sock := {inet:ip_address(), inet:port_number()}, + cert := binary() | undefined, + + %% Private interface. + ref := ranch:ref(), + pid := pid(), + streamid := cowboy_stream:streamid(), + + host_info => cowboy_router:tokens(), + path_info => cowboy_router:tokens(), + bindings => cowboy_router:bindings(), + + has_body := boolean(), + body_length := non_neg_integer() | undefined, + has_read_body => true, + multipart => {binary(), binary()} | done, + + has_sent_resp => headers | true, + resp_cookies => #{iodata() => iodata()}, + resp_headers => #{binary() => iodata()}, + resp_body => resp_body(), + + proxy_header => ranch_proxy_header:proxy_info(), + media_type => {binary(), binary(), [{binary(), binary()}]}, + language => binary() | undefined, + charset => binary() | undefined, + websocket_version => 7 | 8 | 13 +}. -export_type([req/0]). %% Request. diff --git a/src/cowboy_tracer_h.erl b/src/cowboy_tracer_h.erl index bbe10a1..750ff03 100644 --- a/src/cowboy_tracer_h.erl +++ b/src/cowboy_tracer_h.erl @@ -42,6 +42,9 @@ ]. -export_type([tracer_match_specs/0]). +-type tracer_callback() :: fun((init | terminate | tuple(), any()) -> any()). +-export_type([tracer_callback/0]). + -spec init(cowboy_stream:streamid(), cowboy_req:req(), cowboy:opts()) -> {cowboy_stream:commands(), any()}. init(StreamID, Req, Opts) -> |