Rack::Response provides a convenient interface to create a Rack response.
It allows setting of headers and cookies, and provides useful defaults (a OK response containing HTML).
You can use Response#write to iteratively generate your response, but note that this is buffered by Rack::Response until you call finish. finish however can take a block inside which calls to write are syncronous with the Rack response.
Your application’s call should end returning Response#finish.
(Not documented)
# File lib/rack/response.rb, line 21 21: def initialize(body=[], status=200, header={}, &block) 22: @status = status 23: @header = Utils::HeaderHash.new({"Content-Type" => "text/html"}. 24: merge(header)) 25: 26: @writer = lambda { |x| @body << x } 27: @block = nil 28: @length = 0 29: 30: @body = [] 31: 32: if body.respond_to? :to_str 33: write body.to_str 34: elsif body.respond_to?(:each) 35: body.each { |part| 36: write part.to_s 37: } 38: else 39: raise TypeError, "stringable or iterable required" 40: end 41: 42: yield self if block_given? 43: end
(Not documented)
# File lib/rack/response.rb, line 48 48: def [](key) 49: header[key] 50: end
(Not documented)
# File lib/rack/response.rb, line 52 52: def []=(key, value) 53: header[key] = value 54: end
(Not documented)
# File lib/rack/response.rb, line 134 134: def close 135: body.close if body.respond_to?(:close) 136: end
(Not documented)
# File lib/rack/response.rb, line 115 115: def each(&callback) 116: @body.each(&callback) 117: @writer = callback 118: @block.call(self) if @block 119: end
(Not documented)
# File lib/rack/response.rb, line 138 138: def empty? 139: @block == nil && @body.empty? 140: end
(Not documented)
# File lib/rack/response.rb, line 103 103: def finish(&block) 104: @block = block 105: 106: if [204, 304].include?(status.to_i) 107: header.delete "Content-Type" 108: [status.to_i, header.to_hash, []] 109: else 110: [status.to_i, header.to_hash, self] 111: end 112: end
(Not documented)
# File lib/rack/response.rb, line 98 98: def redirect(target, status=302) 99: self.status = status 100: self["Location"] = target 101: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.