mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Fix using custom fields in Req
This commit is contained in:
parent
d14c59d905
commit
42eb6bae69
3 changed files with 16 additions and 2 deletions
|
@ -156,7 +156,7 @@ them by prepending an underscore and the name of your application:
|
||||||
.Setting a custom field
|
.Setting a custom field
|
||||||
[source,erlang]
|
[source,erlang]
|
||||||
----
|
----
|
||||||
Req#{_myapp_auth_method => pubkey}.
|
Req#{'_myapp_auth_method' => pubkey}.
|
||||||
----
|
----
|
||||||
|
|
||||||
=== resp_body()
|
=== resp_body()
|
||||||
|
|
|
@ -160,7 +160,11 @@
|
||||||
charset => binary() | undefined,
|
charset => binary() | undefined,
|
||||||
range => {binary(), binary()
|
range => {binary(), binary()
|
||||||
| [{non_neg_integer(), non_neg_integer() | infinity} | neg_integer()]},
|
| [{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]).
|
-export_type([req/0]).
|
||||||
|
|
||||||
|
|
10
test/handlers/custom_req_fields_h.erl
Normal file
10
test/handlers/custom_req_fields_h.erl
Normal file
|
@ -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}.
|
Loading…
Add table
Add a link
Reference in a new issue