class Rack::Sendfile

def call(env)

def call(env)
  _, headers, body = response = @app.call(env)
  if body.respond_to?(:to_path)
    case type = variation(env)
    when /x-accel-redirect/i
      path = ::File.expand_path(body.to_path)
      if url = map_accel_path(env, path)
        headers[CONTENT_LENGTH] = '0'
        # '?' must be percent-encoded because it is not query string but a part of path
        headers[type.downcase] = ::Rack::Utils.escape_path(url).gsub('?', '%3F')
        obody = body
        response[2] = Rack::BodyProxy.new([]) do
          obody.close if obody.respond_to?(:close)
        end
      else
        env[RACK_ERRORS].puts "x-accel-mapping header missing"
      end
    when /x-sendfile|x-lighttpd-send-file/i
      path = ::File.expand_path(body.to_path)
      headers[CONTENT_LENGTH] = '0'
      headers[type.downcase] = path
      obody = body
      response[2] = Rack::BodyProxy.new([]) do
        obody.close if obody.respond_to?(:close)
      end
    when '', nil
    else
      env[RACK_ERRORS].puts "Unknown x-sendfile variation: '#{type}'.\n"
    end
  end
  response
end