lib/rack/response.rb in rack-1.6.0.beta vs lib/rack/response.rb in rack-1.6.0.beta2
- old
+ new
@@ -18,15 +18,17 @@
# Your application's +call+ should end returning Response#finish.
class Response
attr_accessor :length
+ CHUNKED = 'chunked'.freeze
+ TRANSFER_ENCODING = 'Transfer-Encoding'.freeze
def initialize(body=[], status=200, header={})
@status = status.to_i
@header = Utils::HeaderHash.new.merge(header)
- @chunked = "chunked" == @header['Transfer-Encoding']
+ @chunked = CHUNKED == @header[TRANSFER_ENCODING]
@writer = lambda { |x| @body << x }
@block = nil
@length = 0
@body = []
@@ -70,12 +72,12 @@
def finish(&block)
@block = block
if [204, 205, 304].include?(status.to_i)
- header.delete "Content-Type"
- header.delete "Content-Length"
+ header.delete CONTENT_TYPE
+ header.delete CONTENT_LENGTH
close
[status.to_i, header, []]
else
[status.to_i, header, BodyProxy.new(self){}]
end
@@ -96,11 +98,11 @@
def write(str)
s = str.to_s
@length += Rack::Utils.bytesize(s) unless @chunked
@writer.call s
- header["Content-Length"] = @length.to_s unless @chunked
+ header[CONTENT_LENGTH] = @length.to_s unless @chunked
str
end
def close
body.close if body.respond_to?(:close)
@@ -140,14 +142,14 @@
def include?(header)
!!headers[header]
end
def content_type
- headers["Content-Type"]
+ headers[CONTENT_TYPE]
end
def content_length
- cl = headers["Content-Length"]
+ cl = headers[CONTENT_LENGTH]
cl ? cl.to_i : cl
end
def location
headers["Location"]