Skip to content

Instantly share code, notes, and snippets.

@DouglasAllen
Created August 7, 2015 18:42
Show Gist options
  • Save DouglasAllen/d03dae85d57cf311c290 to your computer and use it in GitHub Desktop.
Save DouglasAllen/d03dae85d57cf311c290 to your computer and use it in GitHub Desktop.
# File lib/rack/sendfile.rb, line 112
def call(env)
status, headers, body = @app.call(env)
if body.respond_to?(:to_path)
case type = variation(env)
when 'X-Accel-Redirect'
path = F.expand_path(body.to_path)
if url = map_accel_path(env, path)
headers[CONTENT_LENGTH] = '0'
headers[type] = url
obody = body
body = 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'
path = F.expand_path(body.to_path)
headers[CONTENT_LENGTH] = '0'
headers[type] = path
obody = body
body = 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
[status, headers, body]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment