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::SUPPORTED_METHODS

Instance Attribute Summary

Attributes inherited from HTTPProxyServer

#callbacks

Instance Method Summary collapse

Methods inherited from HTTPProxyServer

define_callback_methods, #do_DELETE, #do_OPTIONS, #do_PATCH, #do_PUT, #exit, #initialize, #restart, #start, #stop

Constructor Details

This class inherits a constructor from EvilProxy::HTTPProxyServer

Instance Method Details

#fire(key, *args) ⇒ Object



12
13
14
# File 'lib/evil-proxy/agentproxy.rb', line 12

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

#initialize_callbacks(config) ⇒ Object



8
9
10
# File 'lib/evil-proxy/agentproxy.rb', line 8

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

#perform_proxy_request(req, res) ⇒ Object



16
17
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
# File 'lib/evil-proxy/agentproxy.rb', line 16

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

#service(req, res) ⇒ Object



50
51
52
53
54
# File 'lib/evil-proxy/agentproxy.rb', line 50

def service req, res
  fire :before_request, req
  proxy_service req, res
  fire :before_response, req, res
end