cowboy_req:port(3)

NAME

cowboy_req:port - URI port number

DESCRIPTION
    port(Req :: cowboy_req:req()) -> Port :: inet:port_number()

Return the port number of the effective request URI.

Note that the port number returned by this function is obtained by parsing the host header. It may be different from the port the peer used to connect to Cowboy.

The port number can also be obtained using pattern matching:

    #{port := Port} = Req.

ARGUMENTS

Req
    The Req object.

RETURN VALUE

The port number is returned as an integer.

CHANGELOG
    • 2.0: Only the port number is returned, it is no longer wrapped in a tuple.
    • 1.0: Function introduced.

EXAMPLES

Get the effective request URI's port number
    Port = cowboy_req:port(Req).

SEE ALSO

cowboy_req(3)