vendor/rack/lib/rack/response.rb in relevance-castronaut-0.5.4 vs vendor/rack/lib/rack/response.rb in relevance-castronaut-0.6.0
- old
+ new
@@ -21,10 +21,11 @@
@header = Utils::HeaderHash.new({"Content-Type" => "text/html"}.
merge(header))
@writer = lambda { |x| @body << x }
@block = nil
+ @length = 0
@body = []
if body.respond_to? :to_str
write body.to_str
@@ -57,16 +58,17 @@
path = "; path=" + value[:path] if value[:path]
# According to RFC 2109, we need dashes here.
# N.B.: cgi.rb uses spaces...
expires = "; expires=" + value[:expires].clone.gmtime.
strftime("%a, %d-%b-%Y %H:%M:%S GMT") if value[:expires]
+ secure = "; secure" if value[:secure]
value = value[:value]
end
value = [value] unless Array === value
cookie = Utils.escape(key) + "=" +
value.map { |v| Utils.escape v }.join("&") +
- "#{domain}#{path}#{expires}"
+ "#{domain}#{path}#{expires}#{secure}"
case self["Set-Cookie"]
when Array
self["Set-Cookie"] << cookie
when String
@@ -96,10 +98,11 @@
if [204, 304].include?(status.to_i)
header.delete "Content-Type"
[status.to_i, header.to_hash, []]
else
+ header["Content-Length"] ||= @length.to_s
[status.to_i, header.to_hash, self]
end
end
alias to_a finish # For *response
@@ -108,10 +111,12 @@
@writer = callback
@block.call(self) if @block
end
def write(str)
- @writer.call str.to_s
+ s = str.to_s
+ @length += s.size
+ @writer.call s
str
end
def close
body.close if body.respond_to?(:close)