module Roda::RodaPlugins::SinatraHelpers::ResponseMethods
def attachment(filename = nil, disposition=ATTACHMENT)
Set the Content-Disposition to "attachment" with the specified filename,
def attachment(filename = nil, disposition=ATTACHMENT) if filename params = "; filename=#{File.basename(filename).inspect}" unless @headers[CONTENT_TYPE] ext = File.extname(filename) unless ext.empty? content_type(ext) end end end @headers[CONTENT_DISPOSITION] = "#{disposition}#{params}" end
def body(value = (return @body unless block_given?; nil), &block)
Set or retrieve the response body. When a block is given,
def body(value = (return @body unless block_given?; nil), &block) if block @body = DelayedBody.new(&block) else self.body = value end end
def body=(body)
def body=(body) @body = DelayedBody.new{body} end
def client_error?
def client_error? @status.between?(400, 499) if @status end
def content_type(type = (return @headers[CONTENT_TYPE]; nil), opts = OPTS)
Set the Content-Type of the response body given a media type or file
def content_type(type = (return @headers[CONTENT_TYPE]; nil), opts = OPTS) unless (mime_type = mime_type(type) || opts[:default]) raise RodaError, "Unknown media type: #{type}" end unless opts.empty? opts.each do |key, val| next if key == :default || (key == :charset && mime_type.include?(CHARSET)) val = val.inspect if val =~ /[";,]/ mime_type += "#{mime_type.include?(SEMICOLON) ? COMMA : SEMICOLON}#{key}=#{val}" end end @headers[CONTENT_TYPE] = mime_type end
def finish
def finish @length = @body.length if @body.is_a?(DelayedBody) && !@headers[CONTENT_LENGTH] super end
def headers(hash = (return @headers; nil))
Set multiple response headers with Hash, or return the headers if no
def headers(hash = (return @headers; nil)) @headers.merge!(hash) end
def informational?
def informational? @status.between?(100, 199) if @status end
def mime_type(type)
def mime_type(type) roda_class.mime_type(type) end
def not_found?
def not_found? @status == 404 if @status end
def redirect?
def redirect? @status.between?(300, 399) if @status end
def server_error?
def server_error? @status.between?(500, 599) if @status end
def status(value = (return @status; nil))
def status(value = (return @status; nil)) @status = value end
def success?
def success? @status.between?(200, 299) if @status end