Class: Rackdapter::InboundProxyConnection

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/rackdapter/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ InboundProxyConnection

Returns a new instance of InboundProxyConnection.



5
6
7
8
# File 'lib/rackdapter/proxy.rb', line 5

def initialize(*args)
  @app = args.first
  super
end

Instance Method Details

#client_connection=(con) ⇒ Object



10
11
12
# File 'lib/rackdapter/proxy.rb', line 10

def client_connection=(con)
  @request = con
end

#closeObject



38
39
40
# File 'lib/rackdapter/proxy.rb', line 38

def close
  close_connection_after_writing
end

#post_initObject



14
15
16
17
18
19
# File 'lib/rackdapter/proxy.rb', line 14

def post_init
  host,port = "127.0.0.1", @app.next_port
  EventMachine::connect host, port, OutboundProxyConnection, self
  @receive_buffer = ""
  @connected = false
end

#receive_data(data) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rackdapter/proxy.rb', line 21

def receive_data(data)
  @receive_buffer << data
  if @connected
    send data
  else
    if @request
      @connected = true
      send @receive_buffer
    end
  end
end

#send(data) ⇒ Object



33
34
35
36
# File 'lib/rackdapter/proxy.rb', line 33

def send(data)
  # puts "sending to client: #{data}\n---\n"
  @request.send_data(data)
end

#unbindObject



42
43
44
# File 'lib/rackdapter/proxy.rb', line 42

def unbind
  close_connection
end