Class: Hookout::ThinBackend

Inherits:
Thin::Backends::Base
  • Object
show all
Defined in:
lib/hookout/thin_backend.rb

Overview

Backend allowing Thin to act as a Reverse HTTP server

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @server_address = options[:address]
  @label = options[:label]
  
  super()
end

Instance Attribute Details

#labelObject

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_addressObject

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

#connectObject

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

#disconnectObject

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_sObject



30
31
32
# File 'lib/hookout/thin_backend.rb', line 30

def to_s
  "#{@label} via #{@server_address}"
end