100行代码实现的正向代理

2021-01-20  本文已影响0人  翟志军

100行代码只使用Ruby的标准库实现的正向代理程序。

Screenshot from 2021-01-18 20-49-00.png

使用样例

$ forward-proxy --binding 0.0.0.0 --port 3182 --threads 2
[2021-01-14 19:37:47 +1100] INFO Listening 0.0.0.0:3182
[2021-01-14 19:38:24 +1100] INFO CONNECT raw.githubusercontent.com:443 HTTP/1.1

通过命令行使用

Usage: forward-proxy [options]
    -p, --port=PORT                  Bind to specified port. Default: 9292
    -b, --binding=BINDING            Bind to the specified ip. Default: 127.0.0.1
    -t, --threads=THREADS            Specify the number of client threads. Default: 32
    -h, --help                       Prints this help.

通过库引入

require 'forward_proxy'

proxy = ForwardProxy::Server.new(
  bind_address: "127.0.0.1",
  bind_port: 3000
)

proxy.start
上一篇 下一篇

猜你喜欢

热点阅读