Class: ESI::Dispatcher

Inherits:
Mongrel::HttpHandler
  • Object
show all
Includes:
Log
Defined in:
lib/esi/dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#log, #log_debug, #log_error, #log_request, #msg

Constructor Details

#initialize(options) ⇒ Dispatcher

Returns a new instance of Dispatcher.



13
14
15
16
# File 'lib/esi/dispatcher.rb', line 13

def initialize( options )
  super()
  @config = ESI::Config.new( options )
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/esi/dispatcher.rb', line 8

def config
  @config
end

Instance Method Details

#process(request, response) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/esi/dispatcher.rb', line 18

def process(request, response)
  start = Time.now

  url = @config.router.url_for(request.params["REQUEST_URI"])

  chunk_count, bytes_sent, status, sent_from_cache = ESI::Proxy.new(@config).process(url, request,response)

rescue => e
  log_error "\n#{e.message}: error at #{e.backtrace.first} msg at #{__FILE__}:#{__LINE__}\n"
ensure
  log_request "\n#{url}, #{Time.now - start} seconds with status #{status} #{sent_from_cache ? "from cache" : ''} and #{chunk_count} chunks, #{bytes_sent} bytes\n"
end