Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make cowboy_revproxy working with latest version of cowboy.

  • Loading branch information...
commit c552bed42d95dc90685dd6823f934ffbecf275c0 1 parent a976a96
@benoitc authored
View
24 README.md
@@ -58,6 +58,17 @@ Here is a simple example of function proxying the port 8080 to google.com:
cowboy_tcp_transport, [{port, 8080}],
cowboy_revproxy, [{proxy, {?MODULE, proxy}}]).
+To test it do, in the source folder:
+
+ $ rebar get-deps compile
+ $ erl -pa ebin -pa deps/cowboy/ebin
+
+Then in the erlang shell:
+
+ 1> cowboy_revproxy_example:start().
+
+and go on http://127.0.0.1:8080/ , it should display the google page.
+
This simple proxy function allows you to handle an HTTP request locally
@@ -85,16 +96,3 @@ A simple "Hello World" HTTP handler:
terminate(Req, State) ->
ok.
-
-
-
-To test it do, in the source folder:
-
- $ rebar get-deps compile
- $ erl -pa ebin -pa deps/cowboy/ebin
-
-Then in the erlang shell:
-
- 1> cowboy_revproxy_example:start().
-
-and go on http://127.0.0.1:8080/ , it should display the google page.
View
17 src/cowboy_revproxy.erl
@@ -1,7 +1,7 @@
%M% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%%% ex: ft=erlang ts=4 sw=4 et
%%%
-%%% This file is part of cowboy_revproxy released under the MIT license.
+%%% This file is part of cowboy_revproxy released under the MIT license.
%%% See the NOTICE for more information.
@@ -13,6 +13,7 @@
-export([init/4]).
-include_lib("eunit/include/eunit.hrl").
+-include_lib("cowboy/include/http.hrl").
%% proxy state
-record(stproxy, {
@@ -34,10 +35,14 @@
transport :: module(),
dispatch :: cowboy_dispatcher:dispatch_rules(),
handler :: {module(), any()},
+ onrequest :: undefined | fun((#http_req{}) -> #http_req{}),
+ urldecode :: {fun((binary(), T) -> binary()), T},
req_empty_lines = 0 :: integer(),
- max_empty_lines = 5:: integer(),
- max_line_length = 4096:: integer(),
- timeout = 5000 :: timeout(),
+ max_empty_lines :: integer(),
+ req_keepalive = 1 :: integer(),
+ max_keepalive :: integer(),
+ max_line_length :: integer(),
+ timeout :: timeout(),
buffer = <<>> :: binary(),
hibernate = false :: boolean(),
loop_timeout = infinity :: timeout(),
@@ -55,7 +60,7 @@ start_link(ListenerPid, Socket, Transport, Opts) ->
init(ListenerPid, Socket, Transport, Opts) ->
Handler = proplists:get_value(proxy, Opts),
Timeout = proplists:get_value(timeout, Opts, 5000),
- receive shoot -> ok end,
+ ok = cowboy:accept_ack(ListenerPid),
wait_request(#stproxy{listener=ListenerPid, socket=Socket,
transport=Transport, handler=Handler, timeout=Timeout}).
@@ -135,7 +140,7 @@ terminate(#stproxy{socket=Socket, transport=Transport}) ->
remote_connect({Ip, Port}) ->
- {cowboy_tcp_transport, gen_tcp:connect(Ip, Port, [binary,
+ {cowboy_tcp_transport, gen_tcp:connect(Ip, Port, [binary,
{packet, 0}, {delay_send, true}])};
remote_connect({ssl, Ip, Port, Opts}) ->
Opts1 = parse_ssl_options(Opts),
View
7 src/cowboy_revproxy_example.erl
@@ -7,6 +7,7 @@ proxy(_Data) ->
start() ->
application:start(cowboy),
application:start(cowboy_revproxy),
- cowboy:start_listener(http, 100,
- cowboy_tcp_transport, [{port, 8080}],
- cowboy_revproxy, [{proxy, {?MODULE, proxy}}]).
+
+ cowboy:start_listener(http, 100,
+ cowboy_tcp_transport, [{port, 8080}],
+ cowboy_revproxy, [{proxy, {?MODULE, proxy}}]).
Please sign in to comment.
Something went wrong with that request. Please try again.