1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# frozen_string_literal: true
require "webrick/httpproxy"
require "support/black_hole"
require "support/servers/config"
require "support/servers/runner"
class ProxyServer < WEBrick::HTTPProxyServer
include ServerConfig
CONFIG = {
:BindAddress => "127.0.0.1",
:Port => 0,
:AccessLog => BlackHole,
:Logger => BlackHole,
:RequestCallback => proc { |_, res| res["X-PROXIED"] = true }
}.freeze
def initialize
super CONFIG
end
end
class AuthProxyServer < WEBrick::HTTPProxyServer
include ServerConfig
AUTHENTICATOR = proc do |req, res|
WEBrick::HTTPAuth.proxy_basic_auth(req, res, "proxy") do |user, pass|
user == "username" && pass == "password"
end
end
CONFIG = ProxyServer::CONFIG.merge :ProxyAuthProc => AUTHENTICATOR
def initialize
super CONFIG
end
end
|