X7ROOT File Manager
Current Path:
/opt/alt/ruby18/lib64/ruby/gems/1.8/gems/rack-1.6.1/lib/rack
opt
/
alt
/
ruby18
/
lib64
/
ruby
/
gems
/
1.8
/
gems
/
rack-1.6.1
/
lib
/
rack
/
??
..
??
auth
??
backports
??
body_proxy.rb
(958 B)
??
builder.rb
(4.27 KB)
??
cascade.rb
(1.34 KB)
??
chunked.rb
(1.58 KB)
??
commonlogger.rb
(2.28 KB)
??
conditionalget.rb
(2.5 KB)
??
config.rb
(379 B)
??
content_length.rb
(840 B)
??
content_type.rb
(670 B)
??
deflater.rb
(4.57 KB)
??
directory.rb
(4.2 KB)
??
etag.rb
(2.11 KB)
??
file.rb
(4.09 KB)
??
handler
??
handler.rb
(3.24 KB)
??
head.rb
(484 B)
??
lint.rb
(29.26 KB)
??
lobster.rb
(1.97 KB)
??
lock.rb
(601 B)
??
logger.rb
(357 B)
??
methodoverride.rb
(972 B)
??
mime.rb
(30.89 KB)
??
mock.rb
(5.68 KB)
??
multipart
??
multipart.rb
(1.14 KB)
??
nulllogger.rb
(951 B)
??
recursive.rb
(1.73 KB)
??
reloader.rb
(2.97 KB)
??
request.rb
(12.45 KB)
??
response.rb
(4.33 KB)
??
rewindable_input.rb
(3.19 KB)
??
runtime.rb
(961 B)
??
sendfile.rb
(5.18 KB)
??
server.rb
(10.8 KB)
??
session
??
showexceptions.rb
(11.7 KB)
??
showstatus.rb
(3.46 KB)
??
static.rb
(4.87 KB)
??
tempfile_reaper.rb
(670 B)
??
urlmap.rb
(2.46 KB)
??
utils
??
utils.rb
(20.55 KB)
Editing: sendfile.rb
require 'rack/file' require 'rack/body_proxy' module Rack # = Sendfile # # The Sendfile middleware intercepts responses whose body is being # served from a file and replaces it with a server specific X-Sendfile # header. The web server is then responsible for writing the file contents # to the client. This can dramatically reduce the amount of work required # by the Ruby backend and takes advantage of the web server's optimized file # delivery code. # # In order to take advantage of this middleware, the response body must # respond to +to_path+ and the request must include an X-Sendfile-Type # header. Rack::File and other components implement +to_path+ so there's # rarely anything you need to do in your application. The X-Sendfile-Type # header is typically set in your web servers configuration. The following # sections attempt to document # # === Nginx # # Nginx supports the X-Accel-Redirect header. This is similar to X-Sendfile # but requires parts of the filesystem to be mapped into a private URL # hierarchy. # # The following example shows the Nginx configuration required to create # a private "/files/" area, enable X-Accel-Redirect, and pass the special # X-Sendfile-Type and X-Accel-Mapping headers to the backend: # # location ~ /files/(.*) { # internal; # alias /var/www/$1; # } # # location / { # proxy_redirect off; # # proxy_set_header Host $host; # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # # proxy_set_header X-Sendfile-Type X-Accel-Redirect; # proxy_set_header X-Accel-Mapping /var/www/=/files/; # # proxy_pass http://127.0.0.1:8080/; # } # # Note that the X-Sendfile-Type header must be set exactly as shown above. # The X-Accel-Mapping header should specify the location on the file system, # followed by an equals sign (=), followed name of the private URL pattern # that it maps to. The middleware performs a simple substitution on the # resulting path. # # See Also: http://wiki.codemongers.com/NginxXSendfile # # === lighttpd # # Lighttpd has supported some variation of the X-Sendfile header for some # time, although only recent version support X-Sendfile in a reverse proxy # configuration. # # $HTTP["host"] == "example.com" { # proxy-core.protocol = "http" # proxy-core.balancer = "round-robin" # proxy-core.backends = ( # "127.0.0.1:8000", # "127.0.0.1:8001", # ... # ) # # proxy-core.allow-x-sendfile = "enable" # proxy-core.rewrite-request = ( # "X-Sendfile-Type" => (".*" => "X-Sendfile") # ) # } # # See Also: http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModProxyCore # # === Apache # # X-Sendfile is supported under Apache 2.x using a separate module: # # https://tn123.org/mod_xsendfile/ # # Once the module is compiled and installed, you can enable it using # XSendFile config directive: # # RequestHeader Set X-Sendfile-Type X-Sendfile # ProxyPassReverse / http://localhost:8001/ # XSendFile on # # === Mapping parameter # # The third parameter allows for an overriding extension of the # X-Accel-Mapping header. Mappings should be provided in tuples of internal to # external. The internal values may contain regular expression syntax, they # will be matched with case indifference. class Sendfile F = ::File def initialize(app, variation=nil, mappings=[]) @app = app @variation = variation @mappings = mappings.map do |internal, external| [/^#{internal}/i, external] end end 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 private def variation(env) @variation || env['sendfile.type'] || env['HTTP_X_SENDFILE_TYPE'] end def map_accel_path(env, path) if mapping = @mappings.find { |internal,_| internal =~ path } path.sub(*mapping) elsif mapping = env['HTTP_X_ACCEL_MAPPING'] internal, external = mapping.split('=', 2).map{ |p| p.strip } path.sub(/^#{internal}/i, external) end end end end
Upload File
Create Folder