Module: Proxi
- Defined in:
- lib/proxi.rb,
lib/proxi/server.rb,
lib/proxi/listeners.rb,
lib/proxi/reporting.rb,
lib/proxi/connection.rb,
lib/proxi/socket_factory.rb
Overview
## Socket factories
Defined Under Namespace
Classes: Connection, ConsoleReporter, HTTPHostSocketFactory, RequestResponseLogging, SSLSocketFactory, Server, SlowDown, TCPSocketFactory
Class Method Summary collapse
-
.http_host_proxy(local_port, host_mapping) ⇒ Object
‘Proxi.http_host_proxy` allows proxying to multiple remote hosts, based on the HTTP `Host:` header.
-
.tcp_proxy(local_port, remote_host, remote_port) ⇒ Object
With ‘Proxy.tcp_proxy` you get basic proxying from a local port to a remote host and port, all bytes are simply forwarded without caring about their contents.
Class Method Details
.http_host_proxy(local_port, host_mapping) ⇒ Object
‘Proxi.http_host_proxy` allows proxying to multiple remote hosts, based on the HTTP `Host:` header. To use it, gather the IP addresses that correspond to each domain name, and provide this name-to-ip mapping to `http_host_proxy`. Now configure these domain names in `/etc/hosts` to point to the local host, so Proxi can intercept traffic intended for these domains.
For example
Proxi.http_host_proxy(80, {'foo.example.org' => '10.10.0.1'}).call
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/proxi.rb', line 67 def self.http_host_proxy(local_port, host_mapping) reporter = ConsoleReporter.new connection_factory = -> in_socket do socket_factory = HTTPHostSocketFactory.new(host_mapping) Connection .new(in_socket, socket_factory) .subscribe(socket_factory, on: :data_in) .subscribe(reporter) end Server.new(local_port, connection_factory) end |
.tcp_proxy(local_port, remote_host, remote_port) ⇒ Object
With ‘Proxy.tcp_proxy` you get basic proxying from a local port to a remote host and port, all bytes are simply forwarded without caring about their contents.
For example:
Proxi.tcp_proxy(3000, 'foo.example.com', 4000).call
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/proxi.rb', line 46 def self.tcp_proxy(local_port, remote_host, remote_port) reporter = ConsoleReporter.new connection_factory = -> in_socket do socket_factory = TCPSocketFactory.new(remote_host, remote_port) Connection.new(in_socket, socket_factory).subscribe(reporter) end Server.new(local_port, connection_factory) end |