code: public static StringBuilder getBaseRequestUrl(HttpServletRequest request, boolean forceHttps) {
          String scheme = forceHttps ? HTTPS_SCHEME : request.getScheme();
          String serverName = request.getServerName();
          int serverPort = request.getServerPort();
          StringBuilder url = new StringBuilder();
  
          url.append(scheme).append("://").append(serverName);
  
          if (!(scheme.equals(HTTP_SCHEME) && serverPort == DEFAULT_HTTP_PORT) &&
              !(scheme.equals(HTTPS_SCHEME) && serverPort == DEFAULT_HTTPS_PORT)) {
              url.append(":").append(serverPort);
          }
  
          return url;
      }
docs: Returns the portion from the URL that includes the scheme, server name and port number, without the server
  path.
  
  @param request       the request object used to build the base URL
  @param forceHttps    if HTTPS should be enforced
  
  @return the base request URL