Class: EvilProxy::AgentProxyServer

Inherits:
HTTPProxyServer
  • Object
show all
Defined in:
lib/evil-proxy/agentproxy.rb

Constant Summary

Constants inherited from HTTPProxyServer

HTTPProxyServer::DEFAULT_CALLBACKS, HTTPProxyServer::VALID_CALBACKS

Instance Attribute Summary

Attributes inherited from HTTPProxyServer

#callbacks

Instance Method Summary collapse

Methods inherited from HTTPProxyServer

#initialize, #start

Constructor Details

This class inherits a constructor from EvilProxy::HTTPProxyServer

Instance Method Details

#fire(key, *args) ⇒ Object



14
15
16
# File 'lib/evil-proxy/agentproxy.rb', line 14

def fire key, *args
  @mitm_server.fire key, *args, self
end

#initialize_callbacks(config) ⇒ Object



10
11
12
# File 'lib/evil-proxy/agentproxy.rb', line 10

def initialize_callbacks config
  @mitm_server = config[:MITMProxyServer]
end

#perform_proxy_request(req, res) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/evil-proxy/agentproxy.rb', line 18

def perform_proxy_request(req, res)
  uri = req.request_uri
  path = uri.path.dup
  path << "?" << uri.query if uri.query
  header = Hash.new
  choose_header(req, header)
  response = nil

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  http.start do
    if @config[:ProxyTimeout]
      ##################################   these issues are
      http.open_timeout = 30   # secs  #   necessary (maybe because
      http.read_timeout = 60   # secs  #   Ruby's bug, but why?)
      ##################################
    end

    response = yield(http, path, header)
  end

  # Persistent connection requirements are mysterious for me.
  # So I will close the connection in every response.
  res['proxy-connection'] = "close"
  res['connection'] = "close"

  # Convert Net::HTTP::HTTPResponse to WEBrick::HTTPResponse
  res.status = response.code.to_i
  choose_header(response, res)
  set_cookie(response, res)
  res.body = response.body
end