[](key)
click to toggle source
def [](key)
header[key]
end
[]=(key, value)
click to toggle source
def []=(key, value)
header[key] = value
end
close()
click to toggle source
def close
body.close if body.respond_to?(:close)
end
delete_cookie(key, value={})
click to toggle source
def delete_cookie(key, value={})
Utils.delete_cookie_header!(header, key, value)
end
each(&callback)
click to toggle source
def each(&callback)
@body.each(&callback)
@writer = callback
@block.call(self) if @block
end
empty?()
click to toggle source
def empty?
@block == nil && @body.empty?
end
finish(&block)
click to toggle source
def finish(&block)
@block = block
if [204, 205, 304].include?(status.to_i)
header.delete CONTENT_TYPE
header.delete CONTENT_LENGTH
close
[status.to_i, header, []]
else
[status.to_i, header, BodyProxy.new(self){}]
end
end
redirect(target, status=302)
click to toggle source
def redirect(target, status=302)
self.status = status
self["Location"] = target
end
set_cookie(key, value)
click to toggle source
def set_cookie(key, value)
Utils.set_cookie_header!(header, key, value)
end
to_a(&block)
click to toggle source
to_ary(&block)
click to toggle source
write(str)
click to toggle source
Append to body and update Content-Length.
NOTE: Do not mix write and
direct body access!
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
str
end