mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 20:50:24 +00:00
Introduce cowboy_req:sock/1 and cowboy_req:cert/1
To obtain the local socket ip/port and the client TLS certificate, respectively.
This commit is contained in:
parent
4090adaecc
commit
ef58e15547
9 changed files with 268 additions and 35 deletions
|
@ -110,6 +110,7 @@ gun_open(Config, Opts) ->
|
|||
{ok, ConnPid} = gun:open("localhost", config(port, Config), Opts#{
|
||||
retry => 0,
|
||||
transport => config(type, Config),
|
||||
transport_opts => proplists:get_value(transport_opts, Config, []),
|
||||
protocols => [config(protocol, Config)]
|
||||
}),
|
||||
ConnPid.
|
||||
|
|
|
@ -134,6 +134,30 @@ bindings(Config) ->
|
|||
<<"#{key => <<\"bindings\">>}">> = do_get_body("/bindings", Config),
|
||||
ok.
|
||||
|
||||
cert(Config) ->
|
||||
case config(type, Config) of
|
||||
tcp -> doc("TLS certificates can only be provided over TLS.");
|
||||
ssl -> do_cert(Config)
|
||||
end.
|
||||
|
||||
do_cert(Config0) ->
|
||||
doc("A client TLS certificate was provided."),
|
||||
{CaCert, Cert, Key} = ct_helper:make_certs(),
|
||||
Config = [{transport_opts, [
|
||||
{cert, Cert},
|
||||
{key, Key},
|
||||
{cacerts, [CaCert]}
|
||||
]}|Config0],
|
||||
Cert = do_get_body("/cert", Config),
|
||||
Cert = do_get_body("/direct/cert", Config),
|
||||
ok.
|
||||
|
||||
cert_undefined(Config) ->
|
||||
doc("No client TLS certificate was provided."),
|
||||
<<"undefined">> = do_get_body("/cert", Config),
|
||||
<<"undefined">> = do_get_body("/direct/cert", Config),
|
||||
ok.
|
||||
|
||||
header(Config) ->
|
||||
doc("Request header with/without default."),
|
||||
<<"value">> = do_get_body("/args/header/defined", [{<<"defined">>, "value"}], Config),
|
||||
|
@ -274,7 +298,7 @@ path_info(Config) ->
|
|||
ok.
|
||||
|
||||
peer(Config) ->
|
||||
doc("Request peer."),
|
||||
doc("Remote socket address."),
|
||||
<<"{{127,0,0,1},", _/bits >> = do_get_body("/peer", Config),
|
||||
<<"{{127,0,0,1},", _/bits >> = do_get_body("/direct/peer", Config),
|
||||
ok.
|
||||
|
@ -309,6 +333,12 @@ do_scheme(Path, Config) ->
|
|||
<<"https">> when Transport =:= ssl -> ok
|
||||
end.
|
||||
|
||||
sock(Config) ->
|
||||
doc("Local socket address."),
|
||||
<<"{{127,0,0,1},", _/bits >> = do_get_body("/sock", Config),
|
||||
<<"{{127,0,0,1},", _/bits >> = do_get_body("/direct/sock", Config),
|
||||
ok.
|
||||
|
||||
uri(Config) ->
|
||||
doc("Request URI building/modification."),
|
||||
Scheme = case config(type, Config) of
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue