Class: Hookout::ThinBackend
- Inherits:
-
Thin::Backends::Base
- Object
- Thin::Backends::Base
- Hookout::ThinBackend
- Defined in:
- lib/hookout/thin_backend.rb
Overview
Backend allowing Thin to act as a Reverse HTTP server
Instance Attribute Summary collapse
-
#label ⇒ Object
Address and port on which the server is listening for connections.
-
#server_address ⇒ Object
Address and port on which the server is listening for connections.
Instance Method Summary collapse
-
#connect ⇒ Object
Connect the server.
-
#disconnect ⇒ Object
Stops the server.
- #handle_request(request) ⇒ Object
-
#initialize(server, label, options) ⇒ ThinBackend
constructor
A new instance of ThinBackend.
- #to_s ⇒ Object
Constructor Details
#initialize(server, label, options) ⇒ ThinBackend
Returns a new instance of ThinBackend.
7 8 9 10 11 12 |
# File 'lib/hookout/thin_backend.rb', line 7 def initialize(server, label, ) @server_address = [:address] @label = [:label] super() end |
Instance Attribute Details
#label ⇒ Object
Address and port on which the server is listening for connections.
5 6 7 |
# File 'lib/hookout/thin_backend.rb', line 5 def label @label end |
#server_address ⇒ Object
Address and port on which the server is listening for connections.
5 6 7 |
# File 'lib/hookout/thin_backend.rb', line 5 def server_address @server_address end |
Instance Method Details
#connect ⇒ Object
Connect the server
15 16 17 18 19 20 21 22 23 |
# File 'lib/hookout/thin_backend.rb', line 15 def connect @connector = ReverseHttpConnector.new(@label, @server_address, self) @connector.report_poll_exceptions = true @connector.location_change_callback = lambda { |l| puts "Bound to location #{l}" } EventMachine.defer do @connector.start end end |
#disconnect ⇒ Object
Stops the server
26 27 28 |
# File 'lib/hookout/thin_backend.rb', line 26 def disconnect @connector.stop end |
#handle_request(request) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/hookout/thin_backend.rb', line 34 def handle_request(request) connection = ThinConnection.new(request.to_s) connection.rhttp_req = request connection.backend = self initialize_connection(connection) connection.receive_data(request.body) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/hookout/thin_backend.rb', line 30 def to_s "#{@label} via #{@server_address}" end |