module Roda::RodaPlugins::SinatraHelpers::RequestMethods

def back

Alias for referrer
def back
  referrer
end

def error(code=500, body = nil)

and use a 500 status code.
If a single argument is given and it is not an integer, consider it the body
optional body.
Halt processing and return the error status provided with the given code and
def error(code=500, body = nil)
  unless code.is_a?(Integer)
    body = code
    code = 500
  end
  response.status = code
  response.body = body if body
  halt
end

def not_found(body = nil)

Halt processing and return a 404 response with an optional body.
def not_found(body = nil)
  error(404, body)
end

def redirect(path=(no_add_script_name = true; default_redirect_path), status=default_redirect_status)

and update the path.
If the absolute_redirects or :prefixed_redirects roda class options has been set, respect those
def redirect(path=(no_add_script_name = true; default_redirect_path), status=default_redirect_status)
  opts = roda_class.opts
  absolute_redirects = opts[:absolute_redirects]
  prefixed_redirects = no_add_script_name ? false : opts[:prefixed_redirects]
  path = uri(path, absolute_redirects, prefixed_redirects) if absolute_redirects || prefixed_redirects
  super(path, status)
end

def send_file(path, opts = OPTS)

Use the contents of the file at +path+ as the response body. See plugin documentation for options.
def send_file(path, opts = OPTS)
  res = response
  headers = res.headers
  if opts[:type] || !headers[RodaResponseHeaders::CONTENT_TYPE]
    res.content_type(opts[:type] || ::File.extname(path), :default => 'application/octet-stream')
  end
  disposition = opts[:disposition]
  filename    = opts[:filename]
  if disposition || filename
    disposition ||= 'attachment'
    filename = path if filename.nil?
    res.attachment(filename, disposition)
  end
  if lm = opts[:last_modified]
    last_modified(lm)
  end
  file = RACK_FILES.new nil
  s, h, b = if Rack.release > '2'
    file.serving(self, path)
  else
    file.path = path
    file.serving(@env)
  end
  res.status = opts[:status] || s
  headers.delete(RodaResponseHeaders::CONTENT_LENGTH)
  headers.replace(h.merge!(headers))
  res.body = b
  halt
rescue Errno::ENOENT
  not_found
end

def uri(addr = nil, absolute = true, add_script_name = true)

Takes Rack routers and reverse proxies into account.
Generates the absolute URI for a given path in the app.
def uri(addr = nil, absolute = true, add_script_name = true)
  addr = addr.to_s if addr
  return addr if addr =~ /\A[A-z][A-z0-9\+\.\-]*:/
  uri = if absolute
    h = if @env.has_key?("HTTP_X_FORWARDED_HOST") || port != (ssl? ? 443 : 80)
      host_with_port
    else
      host
    end
    ["http#{'s' if ssl?}://#{h}"]
  else
    ['']
  end
  uri << script_name.to_s if add_script_name
  uri << (addr || path_info)
  File.join(uri)
end