ExHttpProxy v1.1.4 HttpProxy
HttpProxy is a simple http proxy.
If you access to particular URL like http://localhost:8080
, then the http_proxy forward the request to other URL
based on configuration.
HttpProcy support two features.
- HttpProxy support multiport proxy fearue.
- HttpProxy support play/record proxied request.
Multiport proxy means that the proxy receives request with particular port and the proxy send request to other address. And you can set the feature against several mulatiple port.
Multiport proxy
For example, you set configuratio like the followings in your project and do mix proxy
. Then the proxy send request to
“http://google.com” if anyone snds to “http://localhost:4000”. And the proxy send request to “http://yahoo.com” if anyone
send request to “http://localhost:4001”.
example
Set configuration as the following in
config/config.exs
.use Mix.Config
config :http_proxy, proxies: [
%{port: 4000, to: "http://google.com"}, %{port: 4001, to: "http://yahoo.com"} ]
record: false, play: true, export_path: “test/example”, play_path: “test/data”
Access to
http://localhost:4000
via Web Browser.- or access to
http://localhost:4001
.
- or access to
The http_proxy forward to http://google.com .
- or forward to http://yahoo.com
Play/Record proxied request.
If you set record: true
in the configuration, the proxy export request into local file as JSON.
You can export requests in particular path which is set as export_path: "test/example"
. Default is “default”.
If you set play: true
in the configuration, the proxy read mapping files and reply them when anyone accesses
to the proxy via particular ports.
Please read test/data/mappings/*.json
if you would like to know the format of playing the reqponse.
Summary
Functions
Start http_proxy.
If the proxy is already running, return {:error, {:already_started, :http_proxy}}
Called when an application is started
Stopt http_proxy
Functions
Start http_proxy.
If the proxy is already running, return {:error, {:already_started, :http_proxy}}
Called when an application is started.
This function is called when an the application is started using
Application.start/2
(and functions on top of that, such as
Application.ensure_started/2
). This function should start the top-level
process of the application (which should be the top supervisor of the
application’s supervision tree if the application follows the OTP design
principles around supervision).
start_type
defines how the application is started:
:normal
- used if the startup is a normal startup or if the application is distributed and is started on the current node because of a failover from another mode and the application specification key:start_phases
is:undefined
.{:takeover, node}
- used if the application is distributed and is started on the current node because of a failover on the nodenode
.{:failover, node}
- used if the application is distributed and is started on the current node because of a failover on nodenode
, and the application specification key:start_phases
is not:undefined
.
start_args
are the arguments passed to the application in the :mod
specification key (e.g., mod: {MyApp, [:my_args]}
).
This function should either return {:ok, pid}
or {:ok, pid, state}
if
startup is successful. pid
should be the PID of the top supervisor. state
can be an arbitrary term, and if omitted will default to []
; if the
application is later stopped, state
is passed to the stop/1
callback (see
the documentation for the c:stop/1
callback for more information).
use Application
provides no default implementation for the start/2
callback.
Callback implementation for Application.start/2
.