diff options
-rw-r--r-- | doc/src/manual/cowboy_req.asciidoc | 2 | ||||
-rw-r--r-- | src/cowboy_req.erl | 6 | ||||
-rw-r--r-- | test/handlers/custom_req_fields_h.erl | 10 |
3 files changed, 16 insertions, 2 deletions
diff --git a/doc/src/manual/cowboy_req.asciidoc b/doc/src/manual/cowboy_req.asciidoc index 2758e8f..ca99f9f 100644 --- a/doc/src/manual/cowboy_req.asciidoc +++ b/doc/src/manual/cowboy_req.asciidoc @@ -156,7 +156,7 @@ them by prepending an underscore and the name of your application: .Setting a custom field [source,erlang] ---- -Req#{_myapp_auth_method => pubkey}. +Req#{'_myapp_auth_method' => pubkey}. ---- === resp_body() diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl index 5633182..60dc86a 100644 --- a/src/cowboy_req.erl +++ b/src/cowboy_req.erl @@ -160,7 +160,11 @@ charset => binary() | undefined, range => {binary(), binary() | [{non_neg_integer(), non_neg_integer() | infinity} | neg_integer()]}, - websocket_version => 7 | 8 | 13 + websocket_version => 7 | 8 | 13, + + %% The user is encouraged to use the Req to store information + %% when no better solution is available. + _ => _ }. -export_type([req/0]). diff --git a/test/handlers/custom_req_fields_h.erl b/test/handlers/custom_req_fields_h.erl new file mode 100644 index 0000000..8d77b2d --- /dev/null +++ b/test/handlers/custom_req_fields_h.erl @@ -0,0 +1,10 @@ +%% This module adds custom fields to the Req object. +%% It is only meant to be checked by Dialyzer. + +-module(custom_req_fields_h). + +-export([init/2]). + +-spec init(Req, Opts) -> {ok, Req, Opts} when Req::cowboy_req:req(). +init(Req, Opts) -> + {ok, Req#{'_myapp_auth_method' => pubkey}, Opts}. |