class Rack::VarnishEsi

Constants

VALID_CONTENT_TYPES
VERSION

Public Class Methods

new(app, options={}) click to toggle source
# File lib/rack/varnish_esi.rb, line 8
def initialize(app, options={})
  @app = app
  @processor = Rack::VarnishEsiProcessor.new(options[:locations] || {})
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/varnish_esi.rb, line 13
def call(env)
  status, headers, body = @app.call(env)

  if headers['Content-Type'] =~ VALID_CONTENT_TYPES
    body.close if body.respond_to?(:close)
    body = @processor.process(body)
    headers['Content-Length'] = (body.reduce(0) {|sum, part| sum + part.bytesize}).to_s
  end

  [status, headers, body]
end