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.to_i
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 100
100: def close
101: body.close if body.respond_to?(:close)
102: end
(Not documented)
# File lib/rack/response.rb, line 81
81: def each(&callback)
82: @body.each(&callback)
83: @writer = callback
84: @block.call(self) if @block
85: end
(Not documented)
# File lib/rack/response.rb, line 104
104: def empty?
105: @block == nil && @body.empty?
106: end
(Not documented)
# File lib/rack/response.rb, line 69
69: def finish(&block)
70: @block = block
71:
72: if [204, 304].include?(status.to_i)
73: header.delete "Content-Type"
74: [status.to_i, header, []]
75: else
76: [status.to_i, header, self]
77: end
78: end
(Not documented)
# File lib/rack/response.rb, line 64
64: def redirect(target, status=302)
65: self.status = status
66: self["Location"] = target
67: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.