Module: Wildcloud::Router::Proxy

Defined in:
lib/wildcloud/router/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#coreObject (readonly)

Returns the value of attribute core.



24
25
26
# File 'lib/wildcloud/router/proxy.rb', line 24

def core
  @core
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



24
25
26
# File 'lib/wildcloud/router/proxy.rb', line 24

def start_time
  @start_time
end

Instance Method Details

#bad_requestObject



80
81
82
83
# File 'lib/wildcloud/router/proxy.rb', line 80

def bad_request
  close_connection(true)
  :stop
end

#closed?Boolean

Tools

Returns:

  • (Boolean)


76
77
78
# File 'lib/wildcloud/router/proxy.rb', line 76

def closed?
  @closed
end

#initialize(core) ⇒ Object



26
27
28
29
# File 'lib/wildcloud/router/proxy.rb', line 26

def initialize(core)
  @core = core
  @closed = false
end

#on_body(chunk) ⇒ Object



66
67
68
# File 'lib/wildcloud/router/proxy.rb', line 66

def on_body(chunk)
  @client.send_data(chunk)
end

#on_headers_complete(headers) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wildcloud/router/proxy.rb', line 54

def on_headers_complete(headers)
  return bad_request unless headers['Host']
  target = @core.resolve(headers['Host'])
  return bad_request unless target
  if target["socket"]
    @client = EventMachine.connect(target["socket"], Router::Client, target)
  else
    @client = EventMachine.connect(target["address"], target["port"], Router::Client, target)
  end
  @client.make_request(self, @parser.http_version.join('.'), @parser.http_method, @parser.request_url, headers)
end

#on_message_beginObject

HTTP parser



50
51
52
# File 'lib/wildcloud/router/proxy.rb', line 50

def on_message_begin
  @start_time = Time.now
end

#on_message_completeObject



70
71
72
# File 'lib/wildcloud/router/proxy.rb', line 70

def on_message_complete
  @parser = nil
end

#post_initObject

EventMachine



33
34
# File 'lib/wildcloud/router/proxy.rb', line 33

def post_init
end

#receive_data(data) ⇒ Object



36
37
38
39
40
41
# File 'lib/wildcloud/router/proxy.rb', line 36

def receive_data(data)
  @parser ||= Http::RequestParser.new(self)
  @parser << data
rescue HTTP::Parser::Error => error
  Router.logger.debug('Proxy') { "Error during parsing #{error.message}" }
end

#send_line(data) ⇒ Object



85
86
87
# File 'lib/wildcloud/router/proxy.rb', line 85

def send_line(data)
  send_data("#{data}\r\n")
end

#unbindObject



43
44
45
46
# File 'lib/wildcloud/router/proxy.rb', line 43

def unbind
  @closed = true
  @client.close_connection(true) if @client and !@client.closed?
end