Class: LighttpdPathinfoFix

Inherits:
Object
  • Object
show all
Defined in:
lib/lighttpd_pathinfo_fix.rb

Overview

Lighttpd sets the wrong SCRIPT_NAME and PATH_INFO if you mount your FastCGI app at “/”. This middleware fixes this issue. This is also modified to account for the case when SCRIPT_NAME is the name of the 404 script

Constant Summary collapse

VERSION =
'1.0.2'
DBG =
'DEBUG_LIGHTTPD_PATH_INFO_FIX'

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ LighttpdPathinfoFix

Returns a new instance of LighttpdPathinfoFix.



9
10
11
# File 'lib/lighttpd_pathinfo_fix.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lighttpd_pathinfo_fix.rb', line 13

def call(env)
  unless env["SERVER_SOFTWARE"].to_s =~ /lightt/i
    inform("Skipping lighttpd pathinfo fix this since this is not a Lighttpd install")
    return @app.call(env)
  end
  
  unless env["PATH_INFO"].to_s.empty?
    inform("Skipping lighttpd pathinfo fix - PATH_INFO was #{env["PATH_INFO"]}")
    return @app.call(env)
  end
  
  # Retreive the actual URI
  uri, qs = env["REQUEST_URI"].to_s.split('?')
  
  # Ensure URI has a leading slash
  uri = "/#{uri}" unless uri =~ /^\//
  munged_env = env.merge("PATH_INFO" => uri, "QUERY_STRING" => qs, "SCRIPT_NAME" => "")
  inform("Munged PATH_INFO to be #{uri}")
  
  @app.call(munged_env)
end