rack-cgi 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/rack/cgi/version.rb +1 -1
- data/lib/rack/cgi.rb +34 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23ac17c5c6d553b31d4845dcd426004f8a38217
|
4
|
+
data.tar.gz: 0cbe4eb000b84c81bcc0c19b82085d4a6d4ba838
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52fb4c084f8afbd23f7842fb7b4f83620ecb2d4ef6960bedc6e2d88074db715a17c549ab308b01a0896e843e989f05e83db0c7fadb60a302f82d864a2cceffc6
|
7
|
+
data.tar.gz: 16486670e4b74e6617303a3550fee17223ef909fa93c5862d46fc84849d500269b59f89c8f7d786846dec2ce60f1b416e0b3c00163d0e473556706d8f03f9c26
|
data/README.md
CHANGED
@@ -54,6 +54,16 @@ If you special `nil`, nothing will happened, as if not matched.
|
|
54
54
|
If you special `""`, script will be launched directly. Ensure script is executable.
|
55
55
|
If you special `path_to_application`, application will be launched with script name.
|
56
56
|
|
57
|
+
### Directory redirect
|
58
|
+
|
59
|
+
In some programs(such as phpBB), when you visit a dir without ending '/'. (Such as 'http://wps-community.org/forum')
|
60
|
+
All relative resource will cannot accessed. In this case, we have to redirect 'http://wps-community.org/forum' to
|
61
|
+
'http://wps-community.org/forum/' to avoid this problem.
|
62
|
+
|
63
|
+
You can use following code to open this feature.
|
64
|
+
|
65
|
+
use Rack::CGI, ..., dir_redirect: true, ...
|
66
|
+
|
57
67
|
TODO
|
58
68
|
----
|
59
69
|
|
data/lib/rack/cgi/version.rb
CHANGED
data/lib/rack/cgi.rb
CHANGED
@@ -7,7 +7,7 @@ module Rack
|
|
7
7
|
::File.executable? rhs
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def initialize app, args = {}
|
12
12
|
@app = app
|
13
13
|
@opts = args.select {|k, _| k.is_a? Symbol}
|
@@ -20,6 +20,8 @@ module Rack
|
|
20
20
|
|
21
21
|
@index = @opts[:index] || []
|
22
22
|
@index = [@index] if not @index.is_a? Array
|
23
|
+
|
24
|
+
@dir_redirect = @opts[:dir_redirect]
|
23
25
|
end
|
24
26
|
|
25
27
|
def solve_path path
|
@@ -27,7 +29,13 @@ module Rack
|
|
27
29
|
if ::File.directory? path
|
28
30
|
@index.each do |f|
|
29
31
|
path2 = ::File.join(path, f)
|
30
|
-
|
32
|
+
if ::File.file? path2
|
33
|
+
if @dir_redirect and path !~ %r{/$}
|
34
|
+
throw :rack_cgi_result, [302, {'Location' => path + '/'}, [""]]
|
35
|
+
else
|
36
|
+
return path2
|
37
|
+
end
|
38
|
+
end
|
31
39
|
end
|
32
40
|
else
|
33
41
|
return path if ::File.file? path
|
@@ -142,31 +150,35 @@ module Rack
|
|
142
150
|
end
|
143
151
|
|
144
152
|
def call(env)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
153
|
+
catch :rack_cgi_result do
|
154
|
+
path = solve_path env["PATH_INFO"]
|
155
|
+
if not path
|
156
|
+
return @app.call(env)
|
157
|
+
end
|
149
158
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
159
|
+
rule = match_cgi_rule path
|
160
|
+
if not rule
|
161
|
+
return @app.call(env)
|
162
|
+
end
|
154
163
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
164
|
+
cgi_env = cgi_env(env, path)
|
165
|
+
code, out, err = run_cgi rule, path, cgi_env
|
166
|
+
if code == 0
|
167
|
+
parse_output out
|
168
|
+
else
|
169
|
+
report_error code, out, err, cgi_env
|
170
|
+
end
|
161
171
|
end
|
162
172
|
end
|
163
173
|
def run(env, rule, path)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
174
|
+
catch :rack_cgi_result do
|
175
|
+
cgi_env = cgi_env(env, path)
|
176
|
+
code, out, err = run_cgi rule, path, cgi_env
|
177
|
+
if code == 0
|
178
|
+
parse_output out
|
179
|
+
else
|
180
|
+
report_error code, out, err, cgi_env
|
181
|
+
end
|
170
182
|
end
|
171
183
|
end
|
172
184
|
end
|