All Projects → KazuCocoa → http_proxy

KazuCocoa / http_proxy

Licence: MIT license
http proxy with Elixir. wait request with multi port and forward to each URIs

Programming Languages

elixir
2628 projects
shell
77523 projects

Projects that are alternatives of or similar to http proxy

small-proxy
Go实现的一个跨平台域名式访问内网穿透工具
Stars: ✭ 49 (-10.91%)
Mutual labels:  http-proxy
ProxyPoolWithUI
Python编写的HTTP代理池,集成WEB管理界面,无外部数据库依赖,可直接运行,兼容Windows,Linux和macOS。Free Proxy Pool with Web UI on Windows, Linux, and macOS.
Stars: ✭ 100 (+81.82%)
Mutual labels:  http-proxy
proxi
Proxy pool. Finds and checks proxies with rest api for querying results. Can find over 25k proxies in under 5 minutes.
Stars: ✭ 32 (-41.82%)
Mutual labels:  http-proxy
nanoproxy
Small fast HTTP forward proxy in Go.
Stars: ✭ 31 (-43.64%)
Mutual labels:  http-proxy
proxy-ng
No description or website provided.
Stars: ✭ 33 (-40%)
Mutual labels:  http-proxy
HttpFilteringEngine
Transparent filtering TLS proxy.
Stars: ✭ 48 (-12.73%)
Mutual labels:  http-proxy
vex
reverse HTTP proxy tunnel via secure SSH connections.
Stars: ✭ 20 (-63.64%)
Mutual labels:  http-proxy
foxy
Session-based Beast/Asio wrapper requiring C++14
Stars: ✭ 61 (+10.91%)
Mutual labels:  http-proxy
serviceq
Super fault-tolerant HTTP load balancer & queue. White paper for reference - https://github.com/gptankit/serviceq-paper
Stars: ✭ 66 (+20%)
Mutual labels:  http-proxy
cute-proxy
A Man-In-The-Middle Proxy as Fiddle and Charles, using Netty, JavaFX
Stars: ✭ 62 (+12.73%)
Mutual labels:  http-proxy
android-sdk
AppSpector is a debugging service for mobile apps
Stars: ✭ 39 (-29.09%)
Mutual labels:  http-proxy
php-proxy
php proxy based on GoAgent protocal,Implemented by golang
Stars: ✭ 85 (+54.55%)
Mutual labels:  http-proxy
swish
C++ HTTP requests for humans
Stars: ✭ 52 (-5.45%)
Mutual labels:  http-proxy
HttpProxy
JAVA实现的IP代理池,支持HTTP与HTTPS两种方式
Stars: ✭ 37 (-32.73%)
Mutual labels:  http-proxy
Pummel
Socks5 Proxy HTTP/HTTPS-Flooding (cc) attack
Stars: ✭ 53 (-3.64%)
Mutual labels:  http-proxy
freeproxy
Get http proxies from some free proxy sites. (爬取免费HTTP代理)
Stars: ✭ 18 (-67.27%)
Mutual labels:  http-proxy
cnn-proxy
Subdomain method that proxies websockets, XMLHttpRequests, and more.
Stars: ✭ 13 (-76.36%)
Mutual labels:  http-proxy
poseidon-medusa
HTTP proxy module based on Poseidon
Stars: ✭ 15 (-72.73%)
Mutual labels:  http-proxy
hyper-reverse-proxy
A simple reverse proxy for use with Hyper and Tokio
Stars: ✭ 94 (+70.91%)
Mutual labels:  http-proxy
rlb
Redirecting Load Balancer
Stars: ✭ 30 (-45.45%)
Mutual labels:  http-proxy

HttpProxy

Elixir CI

codecov

Simple multi HTTP Proxy using Plug. And support record/play requests.

MY GOAL

  • Record/Play proxied requests
    • http_proxy support multi port and multi urls on one execution command mix proxy.
  • Support VCR

architecture

           http_proxy
Client  (server  client)  proxied_server
  |            |            |
  | 1.request  |            |
  |  ------>   | 2.request  |
  |            |  ------>   |
  |            |            |
  |            | 3.response |
  | 4.response |  <------   |
  |  <------   |            |
  |            |            |
  1. The client sends a request to http_proxy, then the http_proxy works as a proxy server.
  2. When the http_proxy receives the request from the client, then the http_proxy sends the request to a proxied server, e.g. http://google.com, as a client.
  3. The http_proxy receives responses from the proxied_server, then the http_proxy sets the response into its response to the client.
  4. The Client receives responses from the http_proxy.

Quick use as http proxy

requirement

  • Elixir over 1.7

set application and deps

  • mix.exs
    • :logger is option.
    • :http_proxy is not need if you run http_proxy with HttpProxy.start/0 or HttpProxy.stop/0 manually.
def application do
  [applications: [:logger, :http_proxy]]
end

...

defp deps do
  [
    {:http_proxy, "~> 1.4.0"}
  ]
end

set configuration

  • config/config.exs
use Mix.Config

config :http_proxy,
  proxies: [
             %{port: 8080,
               to:   "http://google.com"},
             %{port: 8081,
               to:   "http://yahoo.com"}
            ]
  • To manage logger, you should define logger settings like the following.
config :logger, :console,
  level: :info

solve deps and run a server

$ mix deps.get
$ mix clean
$ mix run --no-halt # start proxy server

If you would like to start production mode, you should run with MIX_ENV=prod like the following command.

$ MIX_ENV=prod mix run --no-halt

launch browser

Launch browser and open http://localhost:8080 or http://localhost:8081. Then, http://localhost:8080 redirect to http://google.com and http://localhost:8081 do to http://yahoo.com.

Development

  • Copy pre-commit hook
    • cp hooks/pre-commit ./git/hooks/pre-commit

Configuration

Customize proxy port

  • You can customize a proxy port. For example, if you change a waiting port from 8080 to 4000, then you can access to http://google.com via http://localhost:4000.
use Mix.Config

config :http_proxy,
  proxies: [
             %{port: 4000,
               to:   "http://google.com"},
             %{port: 8081,
               to:   "http://yahoo.com"}
            ]

Add proxy

  • You can add a waiting ports in configuration file. For example, the following setting allow you to access to http://apple.com via http://localhost:8082 in addition.
use Mix.Config

config :http_proxy,
  proxies: [
             %{port: 8080,
               to:   "http://google.com"},
             %{port: 8081,
               to:   "http://yahoo.com"},
             %{port: 8082,
               to:   "http://apple.com"}
            ]

Play and Record mode

  • When :record and :play are false, then the http_proxy works just multi port proxy.
  • When :record is true, then the http_proxy works to record request which is proxied.
  • When :play is true, then the http_proxy works to play request between this the http_proxy and clients.
use Mix.Config

config :http_proxy,
  proxies: [                   # MUST
             %{port: 8080,     # proxy all request even play or record
               to:   "http://google.com"},
             %{port: 8081,
               to:   "http://yahoo.com"}
            ]
  timeout: 20_000,             # Option, ms to wait http request.
  record: false,               # Option, true: record requests. false: don't record.
  play: false,                 # Option, true: play stored requests. false: don't play.
  export_path: "test/example", # Option, path to export recorded files.
  play_path: "test/data"       # Option, path to read json files as response to.

Example

Record request as the following

{
  "request": {
    "headers": [],
    "method": "GET",
    "options": {
      "aspect": "query_params"
    },
    "remote": "127.0.0.1",
    "request_body": "",
    "url": "http://localhost:8080/hoge/inu?email=neko&pass=123"
  },
  "response": {
    "body_file": "path/to/body_file.json",
    "cookies": {},
    "headers": {
      "Cache-Control": "public, max-age=2592000",
      "Content-Length": "251",
      "Content-Type": "text/html; charset=UTF-8",
      "Date": "Sat, 21 Nov 2015 00:37:38 GMT",
      "Expires": "Mon, 21 Dec 2015 00:37:38 GMT",
      "Location": "http://www.google.com/hoge/inu?email=neko&pass=123",
      "Server": "sffe",
      "X-Content-Type-Options": "nosniff",
      "X-XSS-Protection": "1; mode=block"
    },
    "status_code": 301
  }
}

Response body will save in "path/to/body_file.json".

Play request with the following JSON data

  • Example is https://github.com/KazuCocoa/http_proxy/tree/master/test/data/mappings
  • You can set path or path_pattern as attribute under request.
    • If path, the http_proxy check requests are matched completely.
    • If path_pattern, the http_proxy check requests are matched with Regex.
  • You can set body or body_file as attribute under response.
    • If body, the http_proxy send the body string.
    • If body_file, the http_proxy send the body_file binary as response.

path and body case

{
  "request": {
    "path": "/request/path",
    "port": 8080,
    "method": "GET"
  },
  "response": {
    "body": "<html>hello world</html>",
    "cookies": {},
    "headers": {
      "Content-Type": "text/html; charset=UTF-8",
      "Server": "GFE/2.0"
    },
    "status_code": 200
  }
}

path_pattern and body_file case

  • Pattern match with Regex.match?(Regex.compile!("\A/request.*neko\z"), request_path)
  • File.read/2 via file/to/path.json and respond the binary
{
  "request": {
    "path_pattern": "\A/request.*neko\z",
    "port": 8080,
    "method": "GET"
  },
  "response": {
    "body_file": "file/to/path.json",
    "cookies": {},
    "headers": {
      "Content-Type": "text/html; charset=UTF-8",
      "Server": "GFE/2.0"
    },
    "status_code": 200
  }
}

dependencies

$ mix xref graph
lib/http_proxy.ex
└── lib/http_proxy/supervisor.ex
    ├── lib/http_proxy/agent.ex
    │   ├── lib/http_proxy/play/data.ex
    │   │   ├── lib/http_proxy/agent.ex
    │   │   └── lib/http_proxy/play/response.ex
    │   │       ├── lib/http_proxy/play/data.ex
    │   │       └── lib/http_proxy/utils/file.ex
    │   └── lib/http_proxy/play/paths.ex
    │       ├── lib/http_proxy/agent.ex
    │       └── lib/http_proxy/play/response.ex
    └── lib/http_proxy/handle.ex
        ├── lib/http_proxy/play/body.ex
        ├── lib/http_proxy/play/data.ex
        ├── lib/http_proxy/play/paths.ex
        ├── lib/http_proxy/play/response.ex
        └── lib/http_proxy/record/response.ex
            ├── lib/http_proxy/format.ex
            │   └── lib/http_proxy/data.ex (compile)
            └── lib/http_proxy/utils/file.ex

TODO

styleguide

http://elixir.community/styleguide

LICENSE

MIT. Please read LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].