{"id":16889699,"url":"https://github.com/benoitc/cowboy_revproxy","last_synced_at":"2025-03-22T08:31:05.643Z","repository":{"id":1887234,"uuid":"2813150","full_name":"benoitc/cowboy_revproxy","owner":"benoitc","description":"simple TCP routing proxy (layer 7) in erlang","archived":false,"fork":false,"pushed_at":"2015-12-02T21:25:16.000Z","size":13,"stargazers_count":88,"open_issues_count":0,"forks_count":22,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-17T11:52:30.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benoitc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-20T10:06:27.000Z","updated_at":"2024-04-10T20:28:21.000Z","dependencies_parsed_at":"2022-09-07T17:01:44.375Z","dependency_job_id":null,"html_url":"https://github.com/benoitc/cowboy_revproxy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benoitc%2Fcowboy_revproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benoitc%2Fcowboy_revproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benoitc%2Fcowboy_revproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benoitc%2Fcowboy_revproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benoitc","download_url":"https://codeload.github.com/benoitc/cowboy_revproxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244931480,"owners_count":20534007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T16:58:28.583Z","updated_at":"2025-03-22T08:31:05.287Z","avatar_url":"https://github.com/benoitc.png","language":"Erlang","readme":"# cowboy_revproxy\n\ncowboy_revproxy is a simple TCP routing proxy (layer 7) in erlang and\nusing Cowboy connection handling. It lets you configure the routine\nlogic in Erlang. \n\nIf you need to proxy connections to different backend servers depending\non the contents of the transmission, then cowboy_revproxy will helps\nyou. It's heavily inspidered from [proxymachine](https://github.com/mojombo/proxymachine).\n\n\n## Build\n\nYou need [rebar](http://github.com/basho/rebar) to build\ncowboy_revproxy:\n\n    $ rebar get-deps\n    $ rebar compile \n\n## Usage\n\nThe idea is simple, once a request is coming to the proxy the data is\npassed to a proxy function until this function return a remote\nconnection or tell to the proxy to close the connection. \n\n**Valid returns values** are :\n\n* `continue` or `ok` -\u003e wait for next chunk\n* `stop` -\u003e close the connection\n* `{stop, Reply}` -\u003e send Reply to the client and close the connection\n* `{http, Dispatch}` -\u003e Use the HTTP protocol of cowboy with the\n  dispatch rules list Dispatch.\n* `{remote, Remote}` -\u003e return the address of the remote connection to\n  proxy. Remote can be one of the following:\n    - `{ip, port}`\n    - `{ssl, Ip, Port, Options}`, where options are ssl options\n      (keyfile, certfile \u0026 password).\n* `[{remote, Remote}, {data, Data}]` -\u003e same as above, but data passed to\n  the proxy function is replaced by `Data` and will be send to the remote\n  connection.\n* `[{remote, Remote}, {data, Data}, {reply, Reply}]` -\u003e same as above\n  but reply `Reply` to the client.\n\n## Example\n\nHere is a simple example of function proxying the port 8080 to google.com:\n\n    -module(cowboy_revproxy_example).\n    -export([start/0, proxy/1]).\n\n    proxy(_Data) -\u003e\n        {remote, {\"www.google.com\", 80}}.\n\n    start() -\u003e\n        application:start(cowboy),\n        application:start(cowboy_revproxy),\n            cowboy:start_listener(http, 100,\n            cowboy_tcp_transport, [{port, 8080}],\n            cowboy_revproxy, [{proxy, {?MODULE, proxy}}]).\n\nTo test it do, in the source folder:\n\n    $ rebar get-deps compile\n    $ erl -pa ebin -pa deps/cowboy/ebin\n      \nThen in the erlang shell:\n\n    1\u003e cowboy_revproxy_example:start().\n\nand go on http://127.0.0.1:8080/ , it should display the google page.\n\n\nThis simple proxy function allows you to handle an HTTP request locally\n\n\n    proxy(Data) -\u003e\n        Dispatch = [\n            %% {Host, list({Path, Handler, Opts})}\n            {'_', [{'_', my_handler, []}]}\n        ],\n        {http, Dispatch}.\n\n\nA simple \"Hello World\" HTTP handler:\n\n    -module(my_handler).\n    -behaviour(cowboy_http_handler).\n    -export([init/3, handle/2, terminate/2]).\n\n    init({tcp, http}, Req, Opts) -\u003e\n        {ok, Req, undefined_state}.\n\n    handle(Req, State) -\u003e\n        {ok, Req2} = cowboy_http_req:reply(200, [], \u003c\u003c\"Hello World!\"\u003e\u003e, Req),\n        {ok, Req2, State}.\n\n    terminate(Req, State) -\u003e\n        ok.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenoitc%2Fcowboy_revproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenoitc%2Fcowboy_revproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenoitc%2Fcowboy_revproxy/lists"}