Class: AgileProxy::ProxyConnection

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/agile_proxy/proxy_connection.rb

Overview

The Proxy Connection

This class is the event machine connection used by the proxy. Every request creates a new instance of this

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#handlerObject

Returns the value of attribute handler.



16
17
18
# File 'lib/agile_proxy/proxy_connection.rb', line 16

def handler
  @handler
end

Instance Method Details

#on_body(chunk) ⇒ Object



34
35
36
# File 'lib/agile_proxy/proxy_connection.rb', line 34

def on_body(chunk)
  @body << chunk
end

#on_headers_complete(headers) ⇒ Object



30
31
32
# File 'lib/agile_proxy/proxy_connection.rb', line 30

def on_headers_complete(headers)
  @headers = headers
end

#on_message_beginObject



25
26
27
28
# File 'lib/agile_proxy/proxy_connection.rb', line 25

def on_message_begin
  @headers = nil
  @body = ''
end

#on_message_completeObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/agile_proxy/proxy_connection.rb', line 38

def on_message_complete
  if @parser.http_method == 'CONNECT'
    restart_with_ssl(@parser.request_url)
  else
    if @ssl
      uri = URI.parse(@parser.request_url)
      @url = "https://#{@ssl}#{[uri.path, uri.query].compact.join('?')}"
    else
      @url = @parser.request_url
    end
    handle_request
  end
end

#post_initObject



17
18
19
# File 'lib/agile_proxy/proxy_connection.rb', line 17

def post_init
  @parser = Http::Parser.new(self)
end

#receive_data(data) ⇒ Object



21
22
23
# File 'lib/agile_proxy/proxy_connection.rb', line 21

def receive_data(data)
  @parser << data
end