Class: Webmachine::Adapters::Reel

Inherits:
Webmachine::Adapter show all
Defined in:
lib/webmachine/adapters/reel.rb

Instance Attribute Summary

Attributes inherited from Webmachine::Adapter

#configuration, #dispatcher

Instance Method Summary collapse

Methods inherited from Webmachine::Adapter

#initialize, run

Constructor Details

This class inherits a constructor from Webmachine::Adapter

Instance Method Details

#process(connection) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/webmachine/adapters/reel.rb', line 22

def process(connection)
  while wreq = connection.request
    header = Webmachine::Headers[wreq.headers.dup]
    host_parts = header.fetch('Host').split(':')
    path_parts = wreq.url.split('?')
    requri = URI::HTTP.build({}.tap do |h|
      h[:host] = host_parts.first
      h[:port] = host_parts.last.to_i if host_parts.length == 2
      h[:path] = path_parts.first
      h[:query] = path_parts.last if path_parts.length == 2
    end)
    request = Webmachine::Request.new(wreq.method.to_s.upcase,
                                      requri,
                                      header,
                                      LazyRequestBody.new(wreq))
    response = Webmachine::Response.new
    @dispatcher.dispatch(request,response)

    connection.respond ::Reel::Response.new(response.code, response.headers, response.body)
  end
end

#runObject



12
13
14
15
16
17
18
19
20
# File 'lib/webmachine/adapters/reel.rb', line 12

def run
  options = {
    :port => configuration.port,
    :host => configuration.ip
  }.merge(configuration.adapter_options)
  server = ::Reel::Server.supervise(options[:host], options[:port], &method(:process))
  trap("INT"){ server.terminate; exit 0 }
  sleep
end