class Safrano::Response
borrowed fro Sinatra The response object. See Rack::Response and Rack::Response::Helpers for more info: rubydoc.info/github/rack/rack/master/Rack/Response rubydoc.info/github/rack/rack/master/Rack/Response/Helpers
Constants
- DROP_BODY_RESPONSES
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/safrano/response.rb, line 15 def initialize(*) super headers[CONTENT_TYPE] ||= APPJSON_UTF8 end
Public Instance Methods
body=(value)
click to toggle source
# File lib/safrano/response.rb, line 20 def body=(value) value = value.body while ::Rack::Response === value @body = String === value ? [value.to_str] : value end
each()
click to toggle source
Calls superclass method
# File lib/safrano/response.rb, line 25 def each block_given? ? super : enum_for(:each) end
finish()
click to toggle source
# File lib/safrano/response.rb, line 29 def finish result = body if drop_content_info? headers.delete 'Content-Length' headers.delete 'Content-Type' end if drop_body? close result = EMPTY_ARRAY 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'] = calculated_content_length.to_s end [status.to_i, headers, result] end
Private Instance Methods
calculate_content_length?()
click to toggle source
# File lib/safrano/response.rb, line 53 def calculate_content_length? headers['Content-Type'] && !headers['Content-Length'] && (Array === body) end
calculated_content_length()
click to toggle source
# File lib/safrano/response.rb, line 57 def calculated_content_length body.inject(0) { |l, p| l + p.bytesize } end
drop_body?()
click to toggle source
# File lib/safrano/response.rb, line 65 def drop_body? DROP_BODY_RESPONSES.include?(status.to_i) end
drop_content_info?()
click to toggle source
# File lib/safrano/response.rb, line 61 def drop_content_info? (status.to_i / 100 == 1) || drop_body? end