Class: Tunnels::HttpProxy
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Tunnels::HttpProxy
- Defined in:
- lib/tunnels.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(map) ⇒ HttpProxy
constructor
A new instance of HttpProxy.
- #receive_data(data) ⇒ Object
- #relay_from_client(data) ⇒ Object
- #send(data) ⇒ Object
- #unbind ⇒ Object
- #unbind_client(host, port) ⇒ Object
Constructor Details
#initialize(map) ⇒ HttpProxy
Returns a new instance of HttpProxy.
125 126 127 128 129 |
# File 'lib/tunnels.rb', line 125 def initialize(map) map.each do |from, to| make_client from[1], from[2], to[0], to[1], to[2] end end |
Instance Method Details
#receive_data(data) ⇒ Object
131 132 133 |
# File 'lib/tunnels.rb', line 131 def receive_data(data) parser << data unless data.nil? end |
#relay_from_client(data) ⇒ Object
145 146 147 |
# File 'lib/tunnels.rb', line 145 def relay_from_client(data) send_data data unless data.nil? end |
#send(data) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/tunnels.rb', line 135 def send data data.sub!(/\r\nHost:\s*(.+?)\s*\r\n/i) do host, port = $1.split(':') if $1 self.last_client = client host, port "\r\nHost: #{last_client.to_host}:#{last_client.to_port}\r\n" end last_client.send_data data end |
#unbind ⇒ Object
149 150 151 152 |
# File 'lib/tunnels.rb', line 149 def unbind close_all_connections clear_clients end |
#unbind_client(host, port) ⇒ Object
154 155 156 157 |
# File 'lib/tunnels.rb', line 154 def unbind_client host, port close_connection_after_writing clear_client host, port.to_i end |