protected String optionalPort ( HttpServletRequest request ) { if ( "http" . equals ( request . getScheme ( ) ) && request . getServerPort ( ) != 80 || "https" . equals ( request . getScheme ( ) ) && request . getServerPort ( ) != 443 ) { return ":" + request . getServerPort ( ) ; } else { return null ; } }
Returns the HTTP port specified on the given request if it s a non - standard port . The port is considered non - standard if it s not port 80 for insecure request and not port 443 of secure requests .