module Roda::RodaPlugins::Base::ResponseMethods

def [](key)

response['Content-Type'] # => 'text/html'

Return the response header with the given key. Example:
def [](key)
  @headers[key]
end

def []=(key, value)

response['Content-Type'] = 'application/json'

Set the response header with the given key to the given value.
def []=(key, value)
  @headers[key] = value
end

def default_headers

The default headers to use for responses.
def default_headers
  DEFAULT_HEADERS
end

def delete_cookie(key, value = {})

def delete_cookie(key, value = {})
  RodaPlugins.deprecate("RodaResponse#delete_cookie is deprecated and will be removed in Roda 2.  It has been moved to the cookies plugin.")
  ::Rack::Utils.delete_cookie_header!(@headers, key, value)
end

def empty?

response.empty? # => false
response.write('a')
response.empty? # => true

the response as not empty. Example:
that writing an empty string to the response body marks
Whether the response body has been written to yet. Note
def empty?
  @body.empty?
end

def finish

# []]
# {'Content-Type'=>'text/html', 'Content-Length'=>'0'},
# => [200,
response.finish

Example:

size of the response body.
uses a 404 status. Adds the Content-Length header to the
uses a 200 status if the body has been written to, otherwise
for the current response. If the status has not been set,
Return the rack response array of status, headers, and body
def finish
  b = @body
  s = (@status ||= b.empty? ? 404 : 200)
  set_default_headers
  h = @headers
  h[CONTENT_LENGTH] ||= @length.to_s
  [s, h, b]
end

def finish_with_body(body)

body.
and doesn't add the Content-Length header or use the existing
200 response status unless status has been explicitly set,
Return the rack response array using a given body. Assumes a
def finish_with_body(body)
  set_default_headers
  [@status || 200, @headers, body]
end

def initialize

Set the default headers when creating a response.
def initialize
  @status  = nil
  @headers = {}
  @body    = []
  @length  = 0
end

def inspect

Show response class, status code, response headers, and response body
def inspect
  "#<#{self.class.inspect} #{@status.inspect} #{@headers.inspect} #{@body.inspect}>"
end

def redirect(path, status = 302)

response.redirect('bar')
response.redirect('foo', 301)

to the given status. Example:
Set the Location header to the given path, and the status
def redirect(path, status = 302)
  @headers[LOCATION] = path
  @status  = status
end

def roda_class

Return the Roda class related to this response.
def roda_class
  self.class.roda_class
end

def set_cookie(key, value)

def set_cookie(key, value)
  RodaPlugins.deprecate("RodaResponse#set_cookie is deprecated and will be removed in Roda 2.  It has been moved to the cookies plugin.")
  ::Rack::Utils.set_cookie_header!(@headers, key, value)
end

def set_default_headers

response, set the header in the response.
For each default header, if a header has not already been set for the
def set_default_headers
  h = @headers
  default_headers.each do |k,v|
    h[k] ||= v
  end
end

def write(str)

response.write('foo')

Write to the response body. Returns nil.
def write(str)
  s = str.to_s
  @length += s.bytesize
  @body << s
  nil
end