Home

Awesome

sieve

sieve is a simple TCP routing proxy (layer 7) in erlang and using barrel connection handling. It lets you configure the routine logic in Erlang.

If you need to proxy connections to different backend servers depending on the contents of the transmission, then sieve will helps you. It's heavily inspidered from proxymachine.

Build

You need rebar to build cowboy_revproxy:

$ rebar get-deps
$ rebar compile

Usage

The idea is simple, once a request is coming to the proxy the data is passed to a proxy function until this function return a remote connection or tell to the proxy to close the connection.

Valid returns values are :

Example

Here is a simple example of function proxying the port 8080 to google.com:

-module(cowboy_revproxy_example).
-export([start/0, proxy/1]).

proxy(_Data) ->
    {remote, {"openbsd.org", 80}}.

start() ->
    barrel:start(),
    application:start(lager),
    barrel:start_listener(http, 100, barrel_tcp, [{port, 8080}],
                          sieve_revproxy, [{proxy, {?MODULE, proxy}}]).

To test it do, in the source folder:

$ rebar get-deps compile
$ erl -pa ebin -pa deps/barrel/ebin

Then in the erlang shell:

1> sieve_example:start().

and go on http://127.0.0.1:8080/ , it should display the OpenBSD website.