def url_for url_fragment, mode=:path_only
      return url_fragment if url_fragment.include? "://"
      url_fragment = "/#{url_fragment}" unless url_fragment.starts_with? "/"
      case mode
      when :path_only
        base = request.script_name
      when :full
        scheme = request.scheme
        if (scheme == 'http' && request.port == 80 ||
            scheme == 'https' && request.port == 443)
          port = ""
        else
          port = ":#{request.port}"
        end
        base = "#{scheme}://#{request.host}#{port}#{request.script_name}"
      else
        raise TypeError, "Unknown url_for mode #{mode}"
      end
      "#{base}#{url_fragment}"
    end
def url_for url_fragment, mode=:path_only
      return url_fragment if url_fragment.include? "://"
      url_fragment = "/#{url_fragment}" unless url_fragment.starts_with? "/"
      case mode
      when :path_only
        base = request.script_name
      when :full
        scheme = request.scheme
        if (scheme == 'http' && request.port == 80 ||
            scheme == 'https' && request.port == 443)
          port = ""
        else
          port = ":#{request.port}"
        end
        base = "#{scheme}://#{request.host}#{port}#{request.script_name}"
      else
        raise TypeError, "Unknown url_for mode #{mode}"
      end
      "#{base}#{url_fragment}"
    end
Construct a link to +url_fragment+, which should be given relative to
 the base of this Sinatra app.  The mode should be either
 <code>:path_only</code>, which will generate an absolute path within
 the current domain (the default), or <code>:full</code>, which will
 include the site name and port number.  (The latter is typically
 necessary for links in RSS feeds.)  Example usage:

   url_for "/"                                 # "/myapp/"
   url_for "/foo"                              # "/myapp/foo"
   url_for "/foo", :full                       # "http://example.com/myapp/foo"
   url_for "http://bar.com"                    # "http://bar.com"