@ Override public int getVirtualPort ( ) { if ( HeaderStorage . NOTSET != this . iUrlPort ) { // use the port from the parsed URL return this . iUrlPort ; } if ( NOT_PRESENT <= this . iHdrPort ) { // already searched the header value and either found it or not, // either way, return what we saved return this . iHdrPort ; } // need to extract the value from the header byte [ ] host = getHeader ( HttpHeaderKeys . HDR_HOST ) . asBytes ( ) ; if ( null == host || host . length == 0 ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "getVirtualPort: No/empty host header" ) ; } return - 1 ; } // default to not_present now this . iHdrPort = NOT_PRESENT ; int start = - 1 ; if ( LEFT_BRACKET == host [ 0 ] ) { // IPV6 IP address start = GenericUtils . byteIndexOf ( host , RIGHT_BRACKET , 0 ) ; if ( - 1 == start ) { // invalid IP if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "getVirtualPort: Invalid IPV6 ip in host header" ) ; } return - 1 ; } start ++ ; // skip past the bracket } else { // everything but an IPV6 IP start = GenericUtils . byteIndexOf ( host , BNFHeaders . COLON , 0 ) ; } if ( - 1 == start || host . length <= start || BNFHeaders . COLON != host [ start ] ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "getVirtualPort: No port in host header" ) ; } return - 1 ; } start ++ ; // skip past the colon int length = host . length - start ; if ( 0 >= length ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "getVirtualPort: No port after colon" ) ; } return - 1 ; } try { // PK14634 - cache the parsed port this . iHdrPort = GenericUtils . asIntValue ( host , start , length ) ; } catch ( NumberFormatException nfe ) { // no FFDC required if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "getVirtualPort: Invalid port value: " + HttpChannelUtils . getEnglishString ( host , start , length ) ) ; } return - 1 ; } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "getVirtualPort: returning " + this . iHdrPort ) ; } return this . iHdrPort ; }
Query the target port of this request . It will first check for a port in the URL string and if not found it will check the Host header . This will return - 1 if it is not found in either spot .