Class: Tzispa::Http::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- Tzispa::Http::Response
- Defined in:
- lib/tzispa/http/response.rb
Constant Summary collapse
- DROP_BODY_RESPONSES =
[204, 205, 304]
Instance Method Summary collapse
- #body=(value) ⇒ Object
- #each ⇒ Object
- #finish ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
12 13 14 15 |
# File 'lib/tzispa/http/response.rb', line 12 def initialize(*) super headers['Content-Type'] ||= 'text/html' end |
Instance Method Details
#body=(value) ⇒ Object
17 18 19 20 |
# File 'lib/tzispa/http/response.rb', line 17 def body=(value) value = value.body while Rack::Response === value @body = String === value ? [value.to_str] : value end |
#each ⇒ Object
22 23 24 |
# File 'lib/tzispa/http/response.rb', line 22 def each block_given? ? super : enum_for(:each) end |
#finish ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tzispa/http/response.rb', line 26 def finish result = body if drop_content_info? headers.delete "Content-Length" headers.delete "Content-Type" end if drop_body? close result = [] end if calculate_content_length? # if some other code has already set Content-Length, don't muck with it # currently, this would be the static file-handler headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s end headers['X-Powered-By'] = "#{Tzispa::FRAMEWORK_NAME}" [status.to_i, headers, result] end |