• R/O
  • SSH
  • HTTPS

tenarai: 提交


Commit MetaInfo

修訂63 (tree)
時間2008-03-27 22:34:42
作者junkikuchi

Log Message

updated.

Change Summary

差異

--- trunk/test/test_cgi.rb (revision 62)
+++ trunk/test/test_cgi.rb (revision 63)
@@ -8,18 +8,18 @@
88 require 'tenarai/cgi'
99
1010 class CGITest < Test::Unit::TestCase
11- ENCODE1 = 'AaBb123%E3%81%A6%E3%81%Aa%E3%82%89%e3%81%84+x'
12- DECODE1 = 'AaBb123てならい x'
11+ A = 'AaBb123%e3%81%a6%e3%81%aa%e3%82%89%e3%81%84+x'
12+ B = 'AaBb123てならい x'
1313
1414 DATE = Time.local(2007, 6, 5, 22, 10, 0, 0)
1515 DATE_CGI = 'Tue, 05 Jun 2007 13:10:00 GMT'
1616
17- def test_decode
18- assert_equal(ENCODE1, Tenarai::CGI.decode(DECODE1))
17+ def test_escape
18+ assert_equal(A, Tenarai::CGI.escape(B))
1919 end
2020
21- def test_decode
22- assert_equal(DECODE1, Tenarai::CGI.decode(ENCODE1))
21+ def test_unescape
22+ assert_equal(B, Tenarai::CGI.unescape(A))
2323 end
2424
2525 def test_date
--- trunk/lib/tenarai/webrick.rb (revision 62)
+++ trunk/lib/tenarai/webrick.rb (revision 63)
@@ -9,8 +9,8 @@
99 module Tenarai
1010 class WEBrick
1111 class Request < CGI::Request
12- def initialize(request)
13- super(StringIO.new(request.body.to_s), request.meta_vars)
12+ def initialize(request, param)
13+ super(StringIO.new(request.body.to_s), request.meta_vars, param)
1414 end
1515 end
1616
@@ -47,7 +47,7 @@
4747 end
4848
4949 server.mount_proc(param[:path]) do |_request, _response|
50- request = Request.new(_request)
50+ request = Request.new(_request, @param)
5151 response = Response.new(_response)
5252 block.call(request, response)
5353 response.flush
--- trunk/lib/tenarai/cgi/response.rb (revision 62)
+++ trunk/lib/tenarai/cgi/response.rb (revision 63)
@@ -31,7 +31,7 @@
3131 end
3232
3333 def to_s
34- a = ["%s=%s" % [@name, CGI.encode(@value)]]
34+ a = ["%s=%s" % [@name, CGI.escape(@value)]]
3535 @expires && a << "expires=%s" % CGI.date(@expires)
3636 @path && a << "path=%s" % @path
3737 @domain && a << "domain=%s" % @domain
--- trunk/lib/tenarai/cgi/query.rb (revision 62)
+++ trunk/lib/tenarai/cgi/query.rb (revision 63)
@@ -19,7 +19,7 @@
1919 def decode(query)
2020 query.to_s.split(/[&;]/).inject(Query.new) do |ret, q|
2121 key, val = q.split('=')
22- ret[CGI.decode(key)] = CGI.decode(val)
22+ ret[CGI.unescape(key)] = CGI.unescape(val)
2323 ret
2424 end
2525 end
@@ -75,7 +75,7 @@
7575 if v.empty?
7676 ret << key
7777 else
78- ret << "%s=%s" % [key, CGI.encode(v)]
78+ ret << "%s=%s" % [key, CGI.escape(v)]
7979 end
8080 end
8181 else
@@ -82,7 +82,7 @@
8282 if val.empty?
8383 ret << key
8484 else
85- ret << "%s=%s" % [key, CGI.encode(val)]
85+ ret << "%s=%s" % [key, CGI.escape(val)]
8686 end
8787 end
8888 ret
--- trunk/lib/tenarai/cgi.rb (revision 62)
+++ trunk/lib/tenarai/cgi.rb (revision 63)
@@ -9,11 +9,11 @@
99 module Tenarai
1010 class CGI
1111 class << self
12- def encode(s)
12+ def escape(s)
1313 s.to_s.gsub(/[^\w ]/n) do |c| '%%%02x' % c[0] end.tr(' ', '+')
1414 end
1515
16- def decode(s)
16+ def unescape(s)
1717 s.to_s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
1818 [$1.delete('%')].pack('H*')
1919 end
@@ -24,7 +24,9 @@
2424 end
2525 end
2626
27- def initialize(&block)
27+ def initialize(param={} &block)
28+ @param = param
29+
2830 if STDIN.respond_to?(:stat) && STDIN.stat.socket?
2931 require 'fcgi'
3032 FCGI.each do |fcgi|
@@ -36,7 +38,7 @@
3638 end
3739
3840 def dispatch(stdin, stdout, env, &block)
39- request = Request.new(stdin, env)
41+ request = Request.new(stdin, env, @param)
4042 response = Response.new(stdout)
4143 block.call(request, response)
4244 response.flush
--- trunk/lib/tenarai/mongrel.rb (revision 62)
+++ trunk/lib/tenarai/mongrel.rb (revision 63)
@@ -14,8 +14,8 @@
1414 module Tenarai
1515 class Mongrel
1616 class Request < CGI::Request
17- def initialize(request)
18- super(request.body, request.params)
17+ def initialize(request, param)
18+ super(request.body, request.params, param)
1919 end
2020 end
2121
@@ -30,12 +30,13 @@
3030 end
3131
3232 class Handler < ::Mongrel::HttpHandler
33- def initialize(&block)
33+ def initialize(param, &block)
34+ @param = param
3435 @block = block
3536 end
3637
3738 def process(_request, _response)
38- request = Request.new(_request)
39+ request = Request.new(_request, @param)
3940 response = Response.new(_response)
4041 @block.call(request, response)
4142 response.flush
@@ -54,7 +55,7 @@
5455 server.stop
5556 end
5657
57- server.register(param[:path], Mongrel::Handler.new(&block))
58+ server.register(param[:path], Mongrel::Handler.new(@param, &block))
5859 server.run.join
5960 end
6061 end
--- trunk/webapp/Service.rb (revision 62)
+++ trunk/webapp/Service.rb (revision 63)
@@ -97,7 +97,7 @@
9797 aw.min <=> bw.min
9898 end.each do |w, val|
9999 query = val.split(',').map do |v|
100- Tenarai::CGI.decode(v)
100+ Tenarai::CGI.unescape(v)
101101 end
102102 w.init(*query)
103103 end
Show on old repository browser