Skip to content

xek/ranch_proxy_protocol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ranch Proxy Protocol Socket

This module wraps the ranch_tcp module to parse the proxy protocol (version 1) before handing the socket on to the ranch handler.

It has the same API as the ranch_tcp module but with two new functions; connect/4 and proxyname/1.

The transport is called ranch_proxy.

connect/4

connect/4 allows you to connect with to a remote host, and sending the proxy protocol header automatically before going on to use the socket. It's similar to the regular ranch_tcp:connect/3 but accepts a third tuple containing proxy protocol information:

-type proxy_opts() :: [{inet_version, ipv4 | ipv6} |
                       {source_address, inet:ip_address() | inet:hostname()} |
                       {source_port, inet:port_number()} |
                       {dest_address, inet:ip_address() | inet:hostname()} |
                       {source_port, inet:port_number()}].
-spec connect(inet:ip_address() | inet:hostname(),
              inet:port_number(), any(), proxy_opts())
	-> {ok, #proxy_socket{}} | {error, atom()}.

proxyname/1

proxyname/1 gives you the proxy protocol information:

-type proxy_protocol_info() :: [{source_address, inet:ip_address()} |
                                {dest_address, inet:ip_address()} |
                                {source_port, inet:port_number()} |
                                {dest_port, inet:port_number()}].
-spec proxyname(proxy_socket()) -> 
                       {ok, proxy_protocol_info()} | {error, atom()}.

Run the tests!

Sure why don't you

$ rebar get-deps -C rebar.config.test
$ rebar compile ct skip_deps=true -C rebar.config.test

License

See the LICENSE file.

About

PROXY protocol support for ranch

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages