lighttpd_pathinfo_fix 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
data/.gemtest ADDED
File without changes
data/Gemfile ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2011-07-04
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ Gemfile
3
+ History.txt
4
+ Manifest.txt
5
+ README.rdoc
6
+ Rakefile
7
+ lib/lighttpd_pathinfo_fix.rb
8
+ test/test_lighttpd_pathinfo_fix.rb
data/README.rdoc ADDED
@@ -0,0 +1,51 @@
1
+ = lighttpd_pathinfo_fix
2
+
3
+ * http://github.com/julik/lighttpd_pathinfo_fix
4
+
5
+ == DESCRIPTION:
6
+
7
+ This middleware fixes the lighttpd PATH_INFO for apps mounted at / in a way that is compatible with everything.
8
+ That is, in contrast with the Rack documentation this middleware actually fucking works.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ Resets script path variables in the Rack request environment. No side effects now. Will also not intervene
13
+ if the server is not lighttpd.
14
+
15
+ == SYNOPSIS:
16
+
17
+ # In your rackup file or in your Sinatra app
18
+ use LighttpdPathinfoFix
19
+
20
+ == REQUIREMENTS:
21
+
22
+ Ruby > 1.8.5
23
+
24
+ == INSTALL:
25
+
26
+ gem install lighttpd_pathinfo_fix
27
+
28
+ == LICENSE:
29
+
30
+ (The MIT License)
31
+
32
+ Copyright (c) 2011 Julik Tarkhanov
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.spec 'lighttpd_pathinfo_fix' do | s |
7
+ s.developer('Julik Tarkhanov', 'me@julik.nl')
8
+ s.extra_dev_deps = {"flexmock" => "~> 0.8.3 "}
9
+ s.readme_file = 'README.rdoc'
10
+ s.extra_rdoc_files = FileList['*.rdoc'] + FileList['*.txt']
11
+ s.clean_globs = %w( **/.DS_Store coverage.info **/*.rbc .idea .yardoc)
12
+
13
+ end
14
+
15
+ # vim: syntax=ruby
@@ -0,0 +1,25 @@
1
+ # Lighttpd sets the wrong SCRIPT_NAME and PATH_INFO if you mount your
2
+ # FastCGI app at "/".
3
+ # This middleware fixes this issue. This is also
4
+ # modified to account for the case when SCRIPT_NAME is the name of the 404 script
5
+ class LighttpdPathinfoFix
6
+ VERSION = '1.0.0'
7
+
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ return @app.call(env) unless env["FCGI_ROLE"] && (env["SERVER_SOFTWARE"] =~ /lightt/i)
14
+ return @app.call(env) unless env["PATH_INFO"].nil? || env["PATH_INFO"].empty?
15
+
16
+ # Retreive the actual URI
17
+ uri, qs = env["REQUEST_URI"].to_s.split('?')
18
+
19
+ # Ensure URI has a leading slash
20
+ uri = "/#{uri}" unless uri =~ /^\//
21
+ munged_env = env.merge("PATH_INFO" => uri, "QUERY_STRING" => qs, "SCRIPT_NAME" => "")
22
+
23
+ @app.call(munged_env)
24
+ end
25
+ end
@@ -0,0 +1,76 @@
1
+ require "test/unit"
2
+ require "lighttpd_pathinfo_fix"
3
+ require "flexmock"
4
+ require "flexmock/test_unit"
5
+
6
+ class TestLighttpdPathinfoFix < Test::Unit::TestCase
7
+ def setup
8
+ @app = flexmock()
9
+ @fix = LighttpdPathinfoFix.new(@app)
10
+ end
11
+
12
+ def test_bypassed_with_differing_server_name
13
+ source_env = {
14
+ "FCGI_ROLE"=>"RESPONDER",
15
+ "SERVER_SOFTWARE"=>"coffeepot",
16
+ "SCRIPT_NAME"=>"/config.ru",
17
+ "PATH_INFO"=>"",
18
+ "SCRIPT_FILENAME"=>"/Code/apps/flame_bacula_search/config.ru",
19
+ "DOCUMENT_ROOT"=>"/Code/apps/flame_bacula_search",
20
+ "REQUEST_URI"=>"/",
21
+ "REDIRECT_URI"=>"/config.ru",
22
+ "QUERY_STRING"=>"",
23
+ "REQUEST_PATH"=>"/"
24
+ }
25
+ @app.should_receive(:call).with(source_env).once
26
+ @fix.call(source_env)
27
+ end
28
+
29
+ def test_root_path_properly_munged_on_root_path
30
+ source_env = {
31
+ "FCGI_ROLE"=>"RESPONDER",
32
+ "SERVER_SOFTWARE"=>"lighttpd/1.4.19",
33
+ "SCRIPT_NAME"=>"/config.ru",
34
+ "PATH_INFO"=>"",
35
+ "SCRIPT_FILENAME"=>"/Code/apps/flame_bacula_search/config.ru",
36
+ "DOCUMENT_ROOT"=>"/Code/apps/flame_bacula_search",
37
+ "REQUEST_URI"=>"/",
38
+ "REDIRECT_URI"=>"/config.ru",
39
+ "QUERY_STRING"=>"",
40
+ "REQUEST_PATH"=>"/"
41
+ }
42
+
43
+
44
+ dest_env = {
45
+ "FCGI_ROLE"=>"RESPONDER",
46
+ "SERVER_SOFTWARE"=>"lighttpd/1.4.19",
47
+ "SCRIPT_NAME"=>"",
48
+ "PATH_INFO"=>"/",
49
+ "SCRIPT_FILENAME"=>"/Code/apps/flame_bacula_search/config.ru",
50
+ "DOCUMENT_ROOT"=>"/Code/apps/flame_bacula_search",
51
+ "REQUEST_URI"=>"/",
52
+ "REDIRECT_URI"=>"/config.ru",
53
+ "QUERY_STRING"=>nil,
54
+ "REQUEST_PATH"=>"/"
55
+ }
56
+
57
+ @app.should_receive(:call).with(dest_env).once
58
+ @fix.call(source_env)
59
+ end
60
+
61
+ def test_root_path_properly_munged_with_querystring_params
62
+ source = {"FCGI_ROLE"=>"RESPONDER", "SERVER_SOFTWARE"=>"lighttpd/1.4.19",
63
+ "SCRIPT_NAME"=>"/config.ru", "PATH_INFO"=>"",
64
+ "SCRIPT_FILENAME"=>"/Code/apps/flame_bacula_search/config.ru",
65
+ "DOCUMENT_ROOT"=>"/Code/apps/flame_bacula_search",
66
+ "REQUEST_URI"=>"/?foo=bar", "REDIRECT_URI"=>"/config.ru", "QUERY_STRING"=>"", "REQUEST_PATH"=>"/"}
67
+ dest = {"FCGI_ROLE"=>"RESPONDER", "SERVER_SOFTWARE"=>"lighttpd/1.4.19",
68
+ "SCRIPT_NAME"=>"", "PATH_INFO"=>"/", "SCRIPT_FILENAME"=>"/Code/apps/flame_bacula_search/config.ru",
69
+ "DOCUMENT_ROOT"=>"/Code/apps/flame_bacula_search", "REQUEST_URI"=>"/?foo=bar",
70
+ "REDIRECT_URI"=>"/config.ru", "QUERY_STRING"=>"foo=bar", "REQUEST_PATH"=>"/"}
71
+
72
+ @app.should_receive(:call).with(dest).once
73
+ @fix.call(source)
74
+ end
75
+
76
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lighttpd_pathinfo_fix
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Julik Tarkhanov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-04 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: flexmock
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.8.3
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "2.10"
36
+ type: :development
37
+ version_requirements: *id002
38
+ description: |-
39
+ This middleware fixes the lighttpd PATH_INFO for apps mounted at / in a way that is compatible with everything.
40
+ That is, in contrast with the Rack documentation this middleware actually fucking works.
41
+ email:
42
+ - me@julik.nl
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files:
48
+ - History.txt
49
+ - Manifest.txt
50
+ - README.rdoc
51
+ files:
52
+ - .autotest
53
+ - Gemfile
54
+ - History.txt
55
+ - Manifest.txt
56
+ - README.rdoc
57
+ - Rakefile
58
+ - lib/lighttpd_pathinfo_fix.rb
59
+ - test/test_lighttpd_pathinfo_fix.rb
60
+ - .gemtest
61
+ has_rdoc: true
62
+ homepage: http://github.com/julik/lighttpd_pathinfo_fix
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --main
68
+ - README.rdoc
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project: lighttpd_pathinfo_fix
86
+ rubygems_version: 1.6.2
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: This middleware fixes the lighttpd PATH_INFO for apps mounted at / in a way that is compatible with everything
90
+ test_files:
91
+ - test/test_lighttpd_pathinfo_fix.rb