Class Hookout::ThinBackend
In: lib/hookout/thin_backend.rb
Parent: Thin::Backends::Base

Backend allowing Thin to act as a Reverse HTTP server

Methods

connect   disconnect   handle_request   new   to_s  

Attributes

label  [RW]  Address and port on which the server is listening for connections.
server_address  [RW]  Address and port on which the server is listening for connections.

Public Class methods

[Source]

# File lib/hookout/thin_backend.rb, line 7
    def initialize(server, label, options)
      @server_address = options[:address]
      @label = options[:label]
      
      super()
    end

Public Instance methods

Connect the server

[Source]

# 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

Stops the server

[Source]

# File lib/hookout/thin_backend.rb, line 26
    def disconnect
      @connector.stop
    end

[Source]

# 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

[Source]

# File lib/hookout/thin_backend.rb, line 30
    def to_s
      "#{@label} via #{@server_address}"
    end

[Validate]