defmodule Distr do def init(_type, req, []) do {:ok, req, :no_state} end def terminate(reason, request, state) do :ok end def handle(req, state) do {url, _} = :cowboy_req.url(req) {code, body, headers} = case HTTPoison.request (:get, next_url(url)) do {:ok, resp} -> {resp.status_code, resp.body, resp.headers} {:error, _} -> {500, "

500 - Internal Server Error

", []} end {:ok, reply} = :cowboy_req.reply(code, headers, body, req) {:ok, reply, state} end def next_url(url) do purl = URI.parse(url) "#{purl.scheme}://#{next_host()}#{purl.path}" end def next_host() do :random.seed(:os.timestamp) [next|_] = Enum.shuffle(["127.0.0.3", "127.0.0.4"]) next end end