# File lib/cgikit/handler.rb, line 156
    def application_url( request, is_secure = false, port = nil )
      protocol = nil
      if is_secure == true then
        protocol = 'https://'
      else
        protocol = nil
      end

      domain = request.server_name || 'localhost'

      if port.nil? and request.server_port then
        port = request.server_port.to_i
      end
      if port == 80 then
        port = nil
      end

      script = (request.script_name || @application.path).dup
      script.sub!(/\A\//, '')

      if port then
        protocol ||= 'http://'
        path = "#{protocol}#{domain}:#{port}/#{script}"
        path.gsub!(/\/\Z/, '')
      elsif protocol then
        path = "#{protocol}#{domain}/#{script}"
      else
        path = "/#{script}"
      end
      path
    end