module Sinatra::Helpers

def redirect(uri, *args)

Halt processing and redirect to the URI provided.
def redirect(uri, *args)
  if not uri =~ /^https?:\/\//
    # According to RFC 2616 section 14.30, "the field value consists of a
    # single absolute URI"
    abs_uri = "#{request.scheme}://#{request.host}"
    if request.scheme == 'https' && request.port != 443 ||
          request.scheme == 'http' && request.port != 80
      abs_uri << ":#{request.port}"
    end
    uri = (abs_uri << uri)
  end
  status 302
  response['Location'] = uri
  halt(*args)
end