lib/rack/utils.rb in rack-1.5.0.beta.2 vs lib/rack/utils.rb in rack-1.5.0
- old
+ new
@@ -1,10 +1,11 @@
# -*- encoding: binary -*-
require 'fileutils'
require 'set'
require 'tempfile'
require 'rack/multipart'
+require 'time'
major, minor, patch = RUBY_VERSION.split('.').map { |v| v.to_i }
if major == 1 && minor < 9
require 'rack/backports/uri/common_18'
@@ -68,11 +69,10 @@
params = KeySpaceConstrainedParams.new
(qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
next if p.empty?
k, v = p.split('=', 2).map(&unescaper)
- next unless k || v
if cur = params[k]
if cur.class == Array
params[k] << v
else
@@ -248,12 +248,33 @@
case value
when Hash
domain = "; domain=" + value[:domain] if value[:domain]
path = "; path=" + value[:path] if value[:path]
max_age = "; max-age=" + value[:max_age] if value[:max_age]
- # According to RFC 2109, we need dashes here.
- # N.B.: cgi.rb uses spaces...
+ # There is an RFC mess in the area of date formatting for Cookies. Not
+ # only are there contradicting RFCs and examples within RFC text, but
+ # there are also numerous conflicting names of fields and partially
+ # cross-applicable specifications.
+ #
+ # These are best described in RFC 2616 3.3.1. This RFC text also
+ # specifies that RFC 822 as updated by RFC 1123 is preferred. That is a
+ # fixed length format with space-date delimeted fields.
+ #
+ # See also RFC 1123 section 5.2.14.
+ #
+ # RFC 6265 also specifies "sane-cookie-date" as RFC 1123 date, defined
+ # in RFC 2616 3.3.1. RFC 6265 also gives examples that clearly denote
+ # the space delimited format. These formats are compliant with RFC 2822.
+ #
+ # For reference, all involved RFCs are:
+ # RFC 822
+ # RFC 1123
+ # RFC 2109
+ # RFC 2616
+ # RFC 2822
+ # RFC 2965
+ # RFC 6265
expires = "; expires=" +
rfc2822(value[:expires].clone.gmtime) if value[:expires]
secure = "; secure" if value[:secure]
httponly = "; HttpOnly" if value[:httponly]
value = value[:value]
@@ -318,24 +339,29 @@
string.size
end
end
module_function :bytesize
+ def rfc2822(time)
+ time.rfc2822
+ end
+ module_function :rfc2822
+
# Modified version of stdlib time.rb Time#rfc2822 to use '%d-%b-%Y' instead
# of '% %b %Y'.
# It assumes that the time is in GMT to comply to the RFC 2109.
#
# NOTE: I'm not sure the RFC says it requires GMT, but is ambigous enough
# that I'm certain someone implemented only that option.
# Do not use %a and %b from Time.strptime, it would use localized names for
# weekday and month.
#
- def rfc2822(time)
+ def rfc2109(time)
wday = Time::RFC2822_DAY_NAME[time.wday]
mon = Time::RFC2822_MONTH_NAME[time.mon - 1]
time.strftime("#{wday}, %d-#{mon}-%Y %H:%M:%S GMT")
end
- module_function :rfc2822
+ module_function :rfc2109
# Parses the "Range:" header, if present, into an array of Range objects.
# Returns nil if the header is missing or syntactically invalid.
# Returns an empty array if none of the ranges are satisfiable.
def byte_ranges(env, size)