cgialt 0.0.2 → 1.0.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.
- data/CHANGES.txt +21 -2
- data/README.txt +22 -9
- data/bench.rb +3 -3
- data/lib/cgialt.rb +1 -1
- data/lib/cgialt/cookie.rb +7 -5
- data/lib/cgialt/core.rb +92 -70
- data/lib/cgialt/fcgi.rb +3 -3
- data/lib/cgialt/fcgi/cgi_helper.rb +4 -4
- data/lib/cgialt/fcgi/core.rb +50 -50
- data/lib/cgialt/util.rb +71 -27
- data/setup.rb +861 -607
- data/test/test_cgi_cookie.rb +1 -1
- data/test/test_cgi_core.rb +21 -2
- data/test/test_cgi_header.rb +1 -1
- data/test/test_cgi_modruby.rb +1 -1
- data/test/test_cgi_multipart.rb +29 -4
- data/test/test_cgi_util.rb +240 -0
- metadata +41 -33
data/CHANGES.txt
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
## $Rev$
|
2
|
-
## 0.0
|
3
|
-
## copyright(c) 2007 kuwata-lab.com all rights reserved.
|
2
|
+
## 1.0.0
|
3
|
+
## copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
|
4
|
+
|
5
|
+
- release: 1.0.0
|
6
|
+
date: 2008-11-09
|
7
|
+
enhancements:
|
8
|
+
- Ruby 1.9 support
|
9
|
+
- Add tests for 'cgialt/util.rb'.
|
10
|
+
|
11
|
+
changges:
|
12
|
+
- CGI class now uses CGI#env_table() instead of using $CGI_ENV directly.
|
13
|
+
- CGI class now uses CGI#stdinput() and CGI#stdoutput() instead of using $stdin and $stdout directly.
|
14
|
+
- Refactor 'cgialt/fcgi/core.rb'.
|
15
|
+
|
16
|
+
bugfixes:
|
17
|
+
- CGI.parse() supports to parse 'a=10&b' (no '=').
|
18
|
+
- CGI.parse() returned NoMethodError when QUERY_STRING was "&=10". Now fixed.
|
19
|
+
- CGI.unescapeHTML() couldn't convert " ". Now fixed.
|
20
|
+
- Typo fixed in CGI::Cookie.parse().
|
21
|
+
- Move RFC822_DAYS and RFC822_MONTHS from 'cgi/core.rb' to 'cgi/util.rb'.
|
4
22
|
|
5
23
|
|
6
24
|
- release: 0.0.2
|
@@ -9,5 +27,6 @@
|
|
9
27
|
- FastCGI supported. If you required 'cgialt/fcgi' instead of 'fcgi',
|
10
28
|
you can use FCGI.each_cgi() method.
|
11
29
|
|
30
|
+
|
12
31
|
- release: 0.0.1
|
13
32
|
date: 2007-12-09
|
data/README.txt
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
= README.txt
|
2
2
|
|
3
|
-
Release: 0.0
|
3
|
+
Release: 1.0.0
|
4
4
|
|
5
|
-
copyright(c) 2007 kuwata-lab.com all rights reserved.
|
5
|
+
copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
|
6
6
|
|
7
|
+
http://cgialt.rubyforge.org/
|
7
8
|
http://rubyforge.org/projects/cgialt/
|
9
|
+
http://github.com/kwatch/cgialt/
|
8
10
|
|
9
11
|
|
10
12
|
== About
|
@@ -24,13 +26,11 @@ It is written in pure Ruby but works faster than 'cgi.rb'.
|
|
24
26
|
|
25
27
|
== Install
|
26
28
|
|
27
|
-
Download cgialt-0.0.
|
29
|
+
Download cgialt-1.0.0.tar.gz and install it according to the following:
|
28
30
|
|
29
|
-
$ tar xzf cgialt-0.0.
|
30
|
-
$ cd cgialt-0.0
|
31
|
-
$ ruby setup.rb
|
32
|
-
$ ruby setup.rb setup
|
33
|
-
$ sudo ruby setup.rb install
|
31
|
+
$ tar xzf cgialt-1.0.0.tar.gz
|
32
|
+
$ cd cgialt-1.0.0/
|
33
|
+
$ sudo ruby setup.rb
|
34
34
|
|
35
35
|
Or if you have installed RubyGems, you can install CGIAlt by 'gem' command.
|
36
36
|
|
@@ -54,6 +54,19 @@ instead of 'fcgi'.
|
|
54
54
|
require 'cgialt'
|
55
55
|
require 'cgialt/fcgi'
|
56
56
|
|
57
|
+
If you want require 'cgi' when CGIAlt is not installed, try the following.
|
58
|
+
|
59
|
+
begin
|
60
|
+
require 'cgialt'
|
61
|
+
rescue LoadError
|
62
|
+
require 'cgi'
|
63
|
+
end
|
64
|
+
begin
|
65
|
+
reqiure 'cgialt/fcgi'
|
66
|
+
rescue LoadError
|
67
|
+
require 'fcgi'
|
68
|
+
end
|
69
|
+
|
57
70
|
If you want to replace original 'cgi.rb' entirely by 'cgialt',
|
58
71
|
create 'cgi.rb' which requires 'cgialt' under proper directory such as
|
59
72
|
'/usr/local/lib/ruby/site_ruby/1.8'.
|
@@ -65,7 +78,7 @@ When $DEBUG is true or ENV['DEBUG'] is set, CGIAlt prints release number
|
|
65
78
|
to $stderr when loaded.
|
66
79
|
|
67
80
|
$ DEBUG=1 ruby -e 'require "cgi"'
|
68
|
-
*** CGIAlt: release 0.0
|
81
|
+
*** CGIAlt: release 1.0.0
|
69
82
|
|
70
83
|
|
71
84
|
== Benchmark
|
data/bench.rb
CHANGED
data/lib/cgialt.rb
CHANGED
data/lib/cgialt/cookie.rb
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
##
|
8
8
|
## Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
|
9
9
|
##
|
10
|
-
## $Rev
|
11
|
-
## $Release: 0.0
|
12
|
-
## copyright(c) 2007 kuwata-lab.com all rights reserved.
|
10
|
+
## $Rev$
|
11
|
+
## $Release: 1.0.0 $
|
12
|
+
## copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
|
13
13
|
|
14
14
|
class CGI
|
15
15
|
|
@@ -78,7 +78,7 @@ class CGI
|
|
78
78
|
if name.is_a?(String)
|
79
79
|
@name = name
|
80
80
|
@value = value # value is an Array
|
81
|
-
@path = rexp.match($CGI_ENV['SCRIPT_NAME']) ? $& : ''
|
81
|
+
@path = rexp.match($CGI_ENV['SCRIPT_NAME']) ? $& : '' # TODO: remove dependency on $CGI_ENV
|
82
82
|
@secure = false
|
83
83
|
else
|
84
84
|
options = name
|
@@ -213,7 +213,9 @@ class CGI
|
|
213
213
|
name, value = pairs.split('=', 2)
|
214
214
|
next unless name && value
|
215
215
|
name = CGI.unescape(name)
|
216
|
-
values = value.
|
216
|
+
values = value.index('&') \
|
217
|
+
? value.split('&').collect{|v| CGI.unescape(v) } \
|
218
|
+
: [ CGI.unescape(value) ]
|
217
219
|
if cookies.has_key?(name)
|
218
220
|
cookies[name].value.concat(values)
|
219
221
|
else
|
data/lib/cgialt/core.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
##
|
2
|
+
## $Rev$
|
3
|
+
## $Release: 1.0.0 $
|
4
|
+
## copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
|
5
|
+
##
|
6
|
+
|
1
7
|
##
|
2
8
|
## Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
3
9
|
##
|
@@ -7,9 +13,6 @@
|
|
7
13
|
##
|
8
14
|
## Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
|
9
15
|
##
|
10
|
-
## $Rev: 32 $
|
11
|
-
## $Release: 0.0.2 $
|
12
|
-
## copyright(c) 2007 kuwata-lab.com all rights reserved.
|
13
16
|
|
14
17
|
raise "Please, use ruby 1.5.4 or later." if RUBY_VERSION < "1.5.4"
|
15
18
|
|
@@ -271,7 +274,7 @@ class CGI
|
|
271
274
|
#*# Standard internet newline sequence
|
272
275
|
#*EOL = CR + LF
|
273
276
|
#*
|
274
|
-
#*REVISION = '$Id:
|
277
|
+
#*REVISION = '$Id: cgi.rb 12340 2007-05-22 21:58:09Z shyouhei $' #:nodoc:
|
275
278
|
#*
|
276
279
|
#*NEEDS_BINMODE = true if /WIN/ni.match(RUBY_PLATFORM)
|
277
280
|
#*
|
@@ -301,16 +304,10 @@ class CGI
|
|
301
304
|
"VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates",
|
302
305
|
}
|
303
306
|
|
304
|
-
# Abbreviated day-of-week names specified by RFC 822
|
305
|
-
RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
|
306
|
-
|
307
|
-
# Abbreviated month names specified by RFC 822
|
308
|
-
RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
|
309
|
-
|
310
307
|
# :startdoc:
|
311
308
|
|
312
309
|
def env_table
|
313
|
-
|
310
|
+
$CGI_ENV
|
314
311
|
end
|
315
312
|
#*** original
|
316
313
|
#*def env_table
|
@@ -436,10 +433,11 @@ class CGI
|
|
436
433
|
|
437
434
|
def _header_for_string(content_type) #:nodoc:
|
438
435
|
buf = ''
|
436
|
+
env = env_table()
|
439
437
|
if nph?()
|
440
|
-
buf << "#{
|
438
|
+
buf << "#{env['SERVER_PROTOCOL'] || 'HTTP/1.0'} 200 OK#{EOL}"
|
441
439
|
buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
|
442
|
-
buf << "Server: #{
|
440
|
+
buf << "Server: #{env['SERVER_SOFTWARE']}#{EOL}"
|
443
441
|
buf << "Connection: close#{EOL}"
|
444
442
|
end
|
445
443
|
buf << "Content-Type: #{content_type}#{EOL}"
|
@@ -452,6 +450,7 @@ class CGI
|
|
452
450
|
|
453
451
|
def _header_for_hash(options) #:nodoc:
|
454
452
|
buf = ''
|
453
|
+
env = env_table()
|
455
454
|
## add charset to option['type']
|
456
455
|
options['type'] ||= 'text/html'
|
457
456
|
charset = options.delete('charset')
|
@@ -459,12 +458,12 @@ class CGI
|
|
459
458
|
## NPH
|
460
459
|
options.delete('nph') if defined?(MOD_RUBY)
|
461
460
|
if options.delete('nph') || nph?()
|
462
|
-
protocol =
|
461
|
+
protocol = env['SERVER_PROTOCOL'] || 'HTTP/1.0'
|
463
462
|
status = options.delete('status')
|
464
463
|
status = HTTP_STATUS[status] || status || '200 OK'
|
465
464
|
buf << "#{protocol} #{status}#{EOL}"
|
466
465
|
buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
|
467
|
-
options['server'] ||=
|
466
|
+
options['server'] ||= env['SERVER_SOFTWARE'] || ''
|
468
467
|
options['connection'] ||= 'close'
|
469
468
|
end
|
470
469
|
## common headers
|
@@ -507,7 +506,8 @@ class CGI
|
|
507
506
|
private :_header_for_hash
|
508
507
|
|
509
508
|
def nph? #:nodoc:
|
510
|
-
|
509
|
+
env = env_table()
|
510
|
+
return /IIS\/(\d+)/n.match(env['SERVER_SOFTWARE']) && $1.to_i < 5
|
511
511
|
end
|
512
512
|
|
513
513
|
def _header_for_modruby(buf) #:nodoc:
|
@@ -703,7 +703,8 @@ class CGI
|
|
703
703
|
# to "ja".
|
704
704
|
def out(options='text/html') # :yield:
|
705
705
|
options = { 'type' => options } if options.kind_of?(String)
|
706
|
-
stdout =
|
706
|
+
stdout = stdoutput()
|
707
|
+
env = env_table()
|
707
708
|
stdout.binmode if defined? stdout.binmode
|
708
709
|
#if ENV['REQUEST_METHOD'] == 'HEAD'
|
709
710
|
# charset = options['charset']
|
@@ -713,9 +714,9 @@ class CGI
|
|
713
714
|
#end
|
714
715
|
content = yield
|
715
716
|
content = convert_content(content, options)
|
716
|
-
options['length'] = content.
|
717
|
+
options['length'] = _strlen(content).to_s
|
717
718
|
stdout.print header(options)
|
718
|
-
stdout.print content unless
|
719
|
+
stdout.print content unless env['REQUEST_METHOD'] == 'HEAD'
|
719
720
|
end
|
720
721
|
def convert_content(content, options) #:nodoc:
|
721
722
|
charset = options['charset']
|
@@ -734,6 +735,16 @@ class CGI
|
|
734
735
|
return content
|
735
736
|
end
|
736
737
|
private :convert_content
|
738
|
+
if "".respond_to?(:bytesize)
|
739
|
+
def _strlen(str)
|
740
|
+
str.bytesize
|
741
|
+
end
|
742
|
+
else
|
743
|
+
def _strlen(str)
|
744
|
+
str.length
|
745
|
+
end
|
746
|
+
end
|
747
|
+
private :_strlen
|
737
748
|
#*** original
|
738
749
|
#*def out(options = "text/html") # :yield:
|
739
750
|
#*
|
@@ -769,7 +780,7 @@ class CGI
|
|
769
780
|
# cgi = CGI.new
|
770
781
|
# cgi.print # default: cgi.print == $DEFAULT_OUTPUT.print
|
771
782
|
def print(*options)
|
772
|
-
|
783
|
+
stdoutput().print(*options)
|
773
784
|
#*** original
|
774
785
|
#*stdoutput.print(*options)
|
775
786
|
#*** /original
|
@@ -785,8 +796,10 @@ class CGI
|
|
785
796
|
def CGI::parse(query)
|
786
797
|
params = {}
|
787
798
|
query.split(/[&;]/n).each do |pair|
|
788
|
-
key, value = pair.split('=', 2)
|
789
|
-
(params[CGI.unescape(key)] ||= []) << CGI.unescape(value)
|
799
|
+
key, value = pair.split('=', 2) # value is nil when '=' not found
|
800
|
+
#(params[CGI.unescape(key || '')] ||= []) << CGI.unescape(value || '') # desirable
|
801
|
+
key = CGI.unescape(key) if key
|
802
|
+
(params[key] ||= []) << (value ? CGI.unescape(value) : value)
|
790
803
|
end
|
791
804
|
params.default = [].freeze
|
792
805
|
return params
|
@@ -836,88 +849,88 @@ class CGI
|
|
836
849
|
module QueryExtension
|
837
850
|
|
838
851
|
## return Integer(ENV['CONTENT_LENGTH'])
|
839
|
-
def content_length ; return Integer(
|
852
|
+
def content_length ; return Integer(env_table['CONTENT_LENGTH']) ; end
|
840
853
|
|
841
854
|
## return Integer(ENV['SERVER_PORT'])
|
842
|
-
def server_port ; return Integer(
|
855
|
+
def server_port ; return Integer(env_table['SERVER_PORT']) ; end
|
843
856
|
|
844
857
|
## return ENV['AUTH_TYPE']
|
845
|
-
def auth_type ; return
|
858
|
+
def auth_type ; return env_table['AUTH_TYPE'] ; end
|
846
859
|
|
847
860
|
## return ENV['CONTENT_TYPE']
|
848
|
-
def content_type ; return
|
861
|
+
def content_type ; return env_table['CONTENT_TYPE'] ; end
|
849
862
|
|
850
863
|
## return ENV['GATEWAY_INTERFACE']
|
851
|
-
def gateway_interface ; return
|
864
|
+
def gateway_interface ; return env_table['GATEWAY_INTERFACE'] ; end
|
852
865
|
|
853
866
|
## return ENV['PATH_INFO']
|
854
|
-
def path_info ; return
|
867
|
+
def path_info ; return env_table['PATH_INFO'] ; end
|
855
868
|
|
856
869
|
## return ENV['PATH_TRANSLATED']
|
857
|
-
def path_translated ; return
|
870
|
+
def path_translated ; return env_table['PATH_TRANSLATED'] ; end
|
858
871
|
|
859
872
|
## return ENV['QUERY_STRING']
|
860
|
-
def query_string ; return
|
873
|
+
def query_string ; return env_table['QUERY_STRING'] ; end
|
861
874
|
|
862
875
|
## return ENV['REMOTE_ADDR']
|
863
|
-
def remote_addr ; return
|
876
|
+
def remote_addr ; return env_table['REMOTE_ADDR'] ; end
|
864
877
|
|
865
878
|
## return ENV['REMOTE_HOST']
|
866
|
-
def remote_host ; return
|
879
|
+
def remote_host ; return env_table['REMOTE_HOST'] ; end
|
867
880
|
|
868
881
|
## return ENV['REMOTE_IDENT']
|
869
|
-
def remote_ident ; return
|
882
|
+
def remote_ident ; return env_table['REMOTE_IDENT'] ; end
|
870
883
|
|
871
884
|
## return ENV['REMOTE_USER']
|
872
|
-
def remote_user ; return
|
885
|
+
def remote_user ; return env_table['REMOTE_USER'] ; end
|
873
886
|
|
874
887
|
## return ENV['REQUEST_METHOD']
|
875
|
-
def request_method ; return
|
888
|
+
def request_method ; return env_table['REQUEST_METHOD'] ; end
|
876
889
|
|
877
890
|
## return ENV['SCRIPT_NAME']
|
878
|
-
def script_name ; return
|
891
|
+
def script_name ; return env_table['SCRIPT_NAME'] ; end
|
879
892
|
|
880
893
|
## return ENV['SERVER_NAME']
|
881
|
-
def server_name ; return
|
894
|
+
def server_name ; return env_table['SERVER_NAME'] ; end
|
882
895
|
|
883
896
|
## return ENV['SERVER_PROTOCOL']
|
884
|
-
def server_protocol ; return
|
897
|
+
def server_protocol ; return env_table['SERVER_PROTOCOL'] ; end
|
885
898
|
|
886
899
|
## return ENV['SERVER_SOFTWARE']
|
887
|
-
def server_software ; return
|
900
|
+
def server_software ; return env_table['SERVER_SOFTWARE'] ; end
|
888
901
|
|
889
902
|
## return ENV['HTTP_ACCEPT']
|
890
|
-
def accept ; return
|
903
|
+
def accept ; return env_table['HTTP_ACCEPT'] ; end
|
891
904
|
|
892
905
|
## return ENV['HTTP_ACCEPT_CHARSET']
|
893
|
-
def accept_charset ; return
|
906
|
+
def accept_charset ; return env_table['HTTP_ACCEPT_CHARSET'] ; end
|
894
907
|
|
895
908
|
## return ENV['HTTP_ACCEPT_ENCODING']
|
896
|
-
def accept_encoding ; return
|
909
|
+
def accept_encoding ; return env_table['HTTP_ACCEPT_ENCODING'] ; end
|
897
910
|
|
898
911
|
## return ENV['HTTP_ACCEPT_LANGUAGE']
|
899
|
-
def accept_language ; return
|
912
|
+
def accept_language ; return env_table['HTTP_ACCEPT_LANGUAGE'] ; end
|
900
913
|
|
901
914
|
## return ENV['HTTP_CACHE_CONTROL']
|
902
|
-
def cache_control ; return
|
915
|
+
def cache_control ; return env_table['HTTP_CACHE_CONTROL'] ; end
|
903
916
|
|
904
917
|
## return ENV['HTTP_FROM']
|
905
|
-
def from ; return
|
918
|
+
def from ; return env_table['HTTP_FROM'] ; end
|
906
919
|
|
907
920
|
## return ENV['HTTP_HOST']
|
908
|
-
def host ; return
|
921
|
+
def host ; return env_table['HTTP_HOST'] ; end
|
909
922
|
|
910
923
|
## return ENV['HTTP_NEGOTIATE']
|
911
|
-
def negotiate ; return
|
924
|
+
def negotiate ; return env_table['HTTP_NEGOTIATE'] ; end
|
912
925
|
|
913
926
|
## return ENV['HTTP_PRAGMA']
|
914
|
-
def pragma ; return
|
927
|
+
def pragma ; return env_table['HTTP_PRAGMA'] ; end
|
915
928
|
|
916
929
|
## return ENV['HTTP_REFERER']
|
917
|
-
def referer ; return
|
930
|
+
def referer ; return env_table['HTTP_REFERER'] ; end
|
918
931
|
|
919
932
|
## return ENV['HTTP_USER_AGENT']
|
920
|
-
def user_agent ; return
|
933
|
+
def user_agent ; return env_table['HTTP_USER_AGENT'] ; end
|
921
934
|
|
922
935
|
#*** orignal
|
923
936
|
#*%w[ CONTENT_LENGTH SERVER_PORT ].each do |env|
|
@@ -942,7 +955,7 @@ class CGI
|
|
942
955
|
|
943
956
|
# Get the raw cookies as a string.
|
944
957
|
def raw_cookie
|
945
|
-
return
|
958
|
+
return env_table['HTTP_COOKIE']
|
946
959
|
end
|
947
960
|
#*** original
|
948
961
|
#*def raw_cookie
|
@@ -952,7 +965,7 @@ class CGI
|
|
952
965
|
|
953
966
|
# Get the raw RFC2965 cookies as a string.
|
954
967
|
def raw_cookie2
|
955
|
-
return
|
968
|
+
return env_table['HTTP_COOKIE2']
|
956
969
|
end
|
957
970
|
#*** original
|
958
971
|
#*def raw_cookie2
|
@@ -981,7 +994,7 @@ class CGI
|
|
981
994
|
|
982
995
|
def read_multipart(boundary, content_length)
|
983
996
|
## read first boundary
|
984
|
-
stdin =
|
997
|
+
stdin = stdinput()
|
985
998
|
stdin.binmode if defined? stdin.binmode
|
986
999
|
first_line = "--#{boundary}#{EOL}"
|
987
1000
|
content_length -= first_line.length
|
@@ -990,20 +1003,25 @@ class CGI
|
|
990
1003
|
raise EOFError.new("bad content body") unless first_line == status
|
991
1004
|
## parse and set params
|
992
1005
|
params = {}
|
993
|
-
|
1006
|
+
begin
|
1007
|
+
quoted = Regexp.quote(boundary, 'n')
|
1008
|
+
rescue ArgumentError
|
1009
|
+
quoted = Regexp.quote(boundary) # Ruby1.9
|
1010
|
+
end
|
1011
|
+
boundary_rexp = /--#{quoted}(#{EOL}|--)/n
|
994
1012
|
boundary_size = "#{EOL}--#{boundary}#{EOL}".length
|
995
1013
|
boundary_end = nil
|
996
1014
|
buf = ''
|
997
1015
|
bufsize = 10 * 1024
|
998
|
-
|
999
|
-
n = 0
|
1016
|
+
count = MAX_MULTIPART_COUNT
|
1000
1017
|
while true
|
1001
|
-
(
|
1018
|
+
(count -= 1) >= 0 or raise StandardError.new("too many parameters.")
|
1002
1019
|
## create body (StringIO or Tempfile)
|
1003
1020
|
body = create_body(bufsize < content_length)
|
1004
1021
|
class << body
|
1005
1022
|
alias local_path path
|
1006
|
-
attr_reader :original_filename, :content_type
|
1023
|
+
#attr_reader :original_filename, :content_type
|
1024
|
+
attr_accessor :original_filename, :content_type # for Ruby1.9
|
1007
1025
|
end
|
1008
1026
|
## find head and boundary
|
1009
1027
|
head = nil
|
@@ -1042,11 +1060,13 @@ class CGI
|
|
1042
1060
|
/Content-Disposition:.* filename=(?:"(.*?)"|([^;\r\n]*))/ni.match(head)
|
1043
1061
|
filename = $1 || $2 || ''
|
1044
1062
|
filename = CGI.unescape(filename) if unescape_filename?()
|
1045
|
-
body.instance_variable_set('@original_filename', filename.taint)
|
1063
|
+
#body.instance_variable_set('@original_filename', filename.taint)
|
1064
|
+
body.original_filename = filename.taint # for Ruby1.9
|
1046
1065
|
## content type
|
1047
1066
|
/Content-Type: (.*)/ni.match(head)
|
1048
1067
|
(content_type = $1 || '').chomp!
|
1049
|
-
body.instance_variable_set('@content_type', content_type.taint)
|
1068
|
+
#body.instance_variable_set('@content_type', content_type.taint)
|
1069
|
+
body.content_type = content_type.taint # for Ruby1.9
|
1050
1070
|
## query parameter name
|
1051
1071
|
/Content-Disposition:.* name=(?:"(.*?)"|([^;\r\n]*))/ni.match(head)
|
1052
1072
|
name = $1 || $2 || ''
|
@@ -1077,7 +1097,7 @@ class CGI
|
|
1077
1097
|
return body
|
1078
1098
|
end
|
1079
1099
|
def unescape_filename? #:nodoc:
|
1080
|
-
user_agent =
|
1100
|
+
user_agent = env_table['HTTP_USER_AGENT']
|
1081
1101
|
return /Mac/ni.match(user_agent) && /Mozilla/ni.match(user_agent) && !/MSIE/ni.match(user_agent)
|
1082
1102
|
end
|
1083
1103
|
#*** original
|
@@ -1195,7 +1215,7 @@ class CGI
|
|
1195
1215
|
if ARGV.empty?
|
1196
1216
|
string = ARGV.join(' ')
|
1197
1217
|
else
|
1198
|
-
|
1218
|
+
STDIN.tty? and $stderr.puts "(offline mode: enter name=value pairs on standard input)"
|
1199
1219
|
string = readlines().join(' ').gsub(/\n/n, '')
|
1200
1220
|
end
|
1201
1221
|
string = string.gsub(/\\=/n, '%3D').gsub(/\\&/n, '%26')
|
@@ -1235,16 +1255,17 @@ class CGI
|
|
1235
1255
|
# Handles multipart forms (in particular, forms that involve file uploads).
|
1236
1256
|
# Reads query parameters in the @params field, and cookies into @cookies.
|
1237
1257
|
def initialize_query()
|
1238
|
-
|
1258
|
+
env = env_table()
|
1259
|
+
case env_table()['REQUEST_METHOD']
|
1239
1260
|
when 'GET', 'HEAD'
|
1240
|
-
query_str = defined?(MOD_RUBY) ? Apache::request.args :
|
1261
|
+
query_str = defined?(MOD_RUBY) ? Apache::request.args : env['QUERY_STRING']
|
1241
1262
|
@params = CGI.parse(query_str || '')
|
1242
1263
|
@multipart = false
|
1243
1264
|
when 'POST'
|
1244
|
-
content_length = Integer(
|
1245
|
-
if /\Amultipart\/form-data/.match(
|
1265
|
+
content_length = Integer(env['CONTENT_LENGTH'])
|
1266
|
+
if /\Amultipart\/form-data/.match(env['CONTENT_TYPE'])
|
1246
1267
|
raise StandardError.new("too large multipart data.") if content_length > MAX_MULTIPART_LENGTH
|
1247
|
-
unless /boundary=(?:"([^";,]+?)"|([^;,\s]+))/.match(
|
1268
|
+
unless /boundary=(?:"([^";,]+?)"|([^;,\s]+))/.match(env['CONTENT_TYPE'])
|
1248
1269
|
raise StandardError.new("no boundary of multipart data.")
|
1249
1270
|
end
|
1250
1271
|
boundary = $1 || $2
|
@@ -1252,7 +1273,7 @@ class CGI
|
|
1252
1273
|
@multipart = true
|
1253
1274
|
else
|
1254
1275
|
raise StandardError.new("too large post data.") if content_length > MAX_CONTENT_LENGTH
|
1255
|
-
stdin =
|
1276
|
+
stdin = stdinput()
|
1256
1277
|
stdin.binmode if defined? stdin.binmode
|
1257
1278
|
query_str = stdin.read(content_length)
|
1258
1279
|
@params = CGI.parse(query_str || '')
|
@@ -1262,7 +1283,7 @@ class CGI
|
|
1262
1283
|
@params = Hash.new([].freeze)
|
1263
1284
|
@multipart = false
|
1264
1285
|
end
|
1265
|
-
@cookies = CGI::Cookie.parse(
|
1286
|
+
@cookies = CGI::Cookie.parse(env['HTTP_COOKIE'] || env['COOKIE'])
|
1266
1287
|
nil
|
1267
1288
|
end
|
1268
1289
|
private :initialize_query
|
@@ -1396,7 +1417,8 @@ class CGI
|
|
1396
1417
|
# cookies and other parameters are parsed automatically from the standard
|
1397
1418
|
# CGI locations, which varies according to the REQUEST_METHOD.
|
1398
1419
|
def initialize(type=nil)
|
1399
|
-
|
1420
|
+
env = env_table()
|
1421
|
+
if defined?(MOD_RUBY) && !env['GATEWAY_INTERFACE']
|
1400
1422
|
Apache.request.setup_cgi_env
|
1401
1423
|
end
|
1402
1424
|
##
|