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 ; }
Returns the portion from the URL that includes the scheme server name and port number without the server path .