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
- #unbind ⇒ Object
- #unbind_client(host, port) ⇒ Object
Constructor Details
#initialize(map) ⇒ HttpProxy
Returns a new instance of HttpProxy.
128 129 130 131 132 |
# File 'lib/tunnels.rb', line 128 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
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/tunnels.rb', line 134 def receive_data(data) unless data.nil? client = nil data.sub! /\r\nHost:\s*(.+?)\s*\r\n/i do host, port = $1.split(':') if $1 client = client host, port "\r\nHost: #{client.to_host}:#{client.to_port}\r\n" end client.send_data data end end |
#relay_from_client(data) ⇒ Object
147 148 149 |
# File 'lib/tunnels.rb', line 147 def relay_from_client(data) send_data data unless data.nil? end |
#unbind ⇒ Object
151 152 153 154 |
# File 'lib/tunnels.rb', line 151 def unbind close_all_connections clear_clients end |
#unbind_client(host, port) ⇒ Object
156 157 158 159 |
# File 'lib/tunnels.rb', line 156 def unbind_client host, port close_connection_after_writing clear_client host, port.to_i end |