ExHttpProxy v1.5.0 HttpProxy View Source

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.

HttpProxy supports two features.

  1. HttpProxy supports a multi-port proxy.
  2. HttpProxy supports play/record proxied requests.

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

  1. 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"
  2. Access to http://localhost:4000 via Web Browser.

    • or access to http://localhost:4001.
  3. The http_proxy forward to http://google.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.

Link to this section Summary

Functions

Start http_proxy. If the proxy is already running, return {:error, {:already_started, :http_proxy}}

Callback implementation for Application.start/2.

Stopt http_proxy.

Link to this section Functions

Link to this function

start()

View Source
start() :: :ok | {:error, term()}

Start http_proxy. If the proxy is already running, return {:error, {:already_started, :http_proxy}}

Link to this function

start(type, args)

View Source
start(:normal, []) :: {:ok, pid()}

Callback implementation for Application.start/2.

Link to this function

stop()

View Source
stop() :: :ok | {:error, term()}

Stopt http_proxy.