Class: ESI::RackAdapter

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/esi/rack_adapter.rb

Overview

create wrappers for response class ESI::Response < Rack::Response

class Writer
  def initialize( writer )
    @writer = writer
  end
  def write(data)
    @writer.write( data )
  end
end
def socket
  Writer.new(self)
end

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

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

Constructor Details

#initialize(config) ⇒ RackAdapter

Returns a new instance of RackAdapter.



60
61
62
# File 'lib/esi/rack_adapter.rb', line 60

def initialize( config )
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



57
58
59
# File 'lib/esi/rack_adapter.rb', line 57

def config
  @config
end

Instance Method Details

#call(env) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/esi/rack_adapter.rb', line 64

def call(env)
  start = Time.now
  request = ESI::Request.new(env)
  puts request.params["HTTP_VERSION"]

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

  chunk_count = 0, bytes_sent = 0, status = 200, sent_from_cache = false
  Rack::Response.new.finish do |response|
    begin
      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
  end

end

#eachObject



84
85
# File 'lib/esi/rack_adapter.rb', line 84

def each
end