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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 554dbd13cd048c0f09a1f67f40b881aef41b5263
4
- data.tar.gz: b03db17b76eb11c8c5de58fc55bcda9e0e91de95
3
+ metadata.gz: a23ac17c5c6d553b31d4845dcd426004f8a38217
4
+ data.tar.gz: 0cbe4eb000b84c81bcc0c19b82085d4a6d4ba838
5
5
  SHA512:
6
- metadata.gz: 59a84174fd826479e906bac88891a2d0d14664f51c040f4e0383f9e6809efbc4d37ab9accdaa70aee1a5e629cc93112fbc2e718125e0f7575c5fcc53687d1d3c
7
- data.tar.gz: d920cd369e448e4460fab470fb9505554cdcd6a3a3cd3c81c1ab3afda5ff5d76329fbb9bada68324a183beb4c5c9116d4e2e292ae75820a206b13959f3de1f7c
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
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Cgi
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
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
- return path2 if ::File.file? path2
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
- path = solve_path env["PATH_INFO"]
146
- if not path
147
- return @app.call(env)
148
- end
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
- rule = match_cgi_rule path
151
- if not rule
152
- return @app.call(env)
153
- end
159
+ rule = match_cgi_rule path
160
+ if not rule
161
+ return @app.call(env)
162
+ end
154
163
 
155
- cgi_env = cgi_env(env, path)
156
- code, out, err = run_cgi rule, path, cgi_env
157
- if code == 0
158
- parse_output out
159
- else
160
- report_error code, out, err, cgi_env
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
- 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
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cgi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chizhong Jin