summaryrefslogtreecommitdiff
path: root/lib/cgi-lib.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-10-12 04:53:36 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-10-12 04:53:36 +0000
commitbe1fea072cd0d22788ef8a931c0c6b64a2503b5d (patch)
tree4d17e3f2cabbe9f4ea2bee8f523de11ce30f6a39 /lib/cgi-lib.rb
parent758cb647c7ac9e02a9ee0d7cb0934a5c963481e0 (diff)
19991012
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/cgi-lib.rb')
-rw-r--r--lib/cgi-lib.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb
index f599f77..bf04601 100644
--- a/lib/cgi-lib.rb
+++ b/lib/cgi-lib.rb
@@ -117,6 +117,17 @@ class CGI < SimpleDelegator
LF = "\012"
EOL = CR + LF
+ RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
+ RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
+
+ # make rfc1123 date string
+ def rfc1123_date(time)
+ t = time.clone.gmtime
+ return format("%s, %.2d %s %d %.2d:%.2d:%.2d GMT",
+ RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
+ t.hour, t.min, t.sec)
+ end
+
# escape url encode
def escape(str)
str.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
@@ -132,7 +143,7 @@ class CGI < SimpleDelegator
str.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
end
- module_function :escape, :unescape, :escapeHTML
+ module_function :escape, :unescape, :escapeHTML, :rfc1123_date
# offline mode. read name=value pairs on standard input.
def read_from_cmdline
@@ -160,7 +171,7 @@ class CGI < SimpleDelegator
input.read(Integer(ENV['CONTENT_LENGTH'])) or ""
else
read_from_cmdline
- end.split(/&/).each do |x|
+ end.split(/[&;]/).each do |x|
key, val = x.split(/=/,2).collect{|x|unescape(x)}
if @inputs.include?(key)
@inputs[key] += "\0" + (val or "")
@@ -201,7 +212,7 @@ class CGI < SimpleDelegator
"Set-Cookie: " + options['name'] + '=' + escape(options['value']) +
(options['domain'] ? '; domain=' + options['domain'] : '') +
(options['path'] ? '; path=' + options['path'] : '') +
- (options['expires'] ? '; expires=' + options['expires'].strftime("%a, %d %b %Y %X %Z") : '') +
+ (options['expires'] ? '; expires=' + rfc1123_date(options['expires']) : '') +
(options['secure'] ? '; secure' : '')
end
@@ -218,7 +229,7 @@ class CGI < SimpleDelegator
else
if options.delete("nph") or (ENV['SERVER_SOFTWARE'] =~ /IIS/)
[(ENV['SERVER_PROTOCOL'] or "HTTP/1.0") + " 200 OK",
- "Date: " + Time.now.gmtime.strftime("%a, %d %b %Y %X %Z"),
+ "Date: " + rfc1123_date(Time.now),
"Server: " + (ENV['SERVER_SOFTWARE'] or ""),
"Connection: close"] +
(options.empty? ? ["Content-Type: text/html"] : options)