Class: Heroku::Forward::Proxy::Server
- Inherits:
-
Object
- Object
- Heroku::Forward::Proxy::Server
- Defined in:
- lib/heroku/forward/proxy/server.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#retries ⇒ Object
readonly
Returns the value of attribute retries.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #forward!(options = {}) ⇒ Object
-
#initialize(backend, options = {}) ⇒ Server
constructor
A new instance of Server.
- #on_connect(&callback) ⇒ Object
- #stop! ⇒ Object
Constructor Details
#initialize(backend, options = {}) ⇒ Server
Returns a new instance of Server.
9 10 11 12 13 14 |
# File 'lib/heroku/forward/proxy/server.rb', line 9 def initialize(backend, = {}) @host = [:host] || '0.0.0.0' @port = [:port] || 3000 @retries = [:retries] || 10 @backend = backend end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
6 7 8 |
# File 'lib/heroku/forward/proxy/server.rb', line 6 def backend @backend end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/heroku/forward/proxy/server.rb', line 6 def host @host end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/heroku/forward/proxy/server.rb', line 7 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/heroku/forward/proxy/server.rb', line 6 def port @port end |
#retries ⇒ Object (readonly)
Returns the value of attribute retries.
6 7 8 |
# File 'lib/heroku/forward/proxy/server.rb', line 6 def retries @retries end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
6 7 8 |
# File 'lib/heroku/forward/proxy/server.rb', line 6 def start @start end |
Instance Method Details
#forward!(options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/heroku/forward/proxy/server.rb', line 24 def forward!( = {}) @start = Time.now logger.info "Launching Backend ..." if logger backend.spawn! if [:delay] && (delay = [:delay].to_i) > 0 logger.info "Waiting #{delay}s to Launch Proxy Server ..." if logger sleep delay end logger.info "Launching Proxy Server at #{host}:#{port} ..." if logger s = self ::Proxy.start({ :host => host, :port => port, :debug => false }) do |conn| if @start EM.next_tick do s.send(:connect, conn) end else s.send(:connect, conn) end conn.on_connect do s.on_connect end conn.on_data do |data| data end conn.on_response do |backend, resp| resp end conn.on_finish do end end end |
#on_connect(&callback) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/heroku/forward/proxy/server.rb', line 16 def on_connect(&callback) if block_given? @on_connect = callback elsif @on_connect @on_connect.call end end |
#stop! ⇒ Object
67 68 69 70 71 72 |
# File 'lib/heroku/forward/proxy/server.rb', line 67 def stop! logger.info "Terminating Proxy Server" if logger EventMachine.stop logger.info "Terminating Web Server" if logger backend.terminate! end |