public int getHostPort ( ) { String host = requestHeaders . getFirst ( Headers . HOST ) ; if ( host != null ) { //for ipv6 addresses we make sure we take out the first part, which can have multiple occurrences of : final int colonIndex ; if ( host . startsWith ( "[" ) ) { colonIndex = host . indexOf ( ' ' , host . indexOf ( ' ' ) ) ; } else { colonIndex = host . indexOf ( ' ' ) ; } if ( colonIndex != - 1 ) { try { return Integer . parseInt ( host . substring ( colonIndex + 1 ) ) ; } catch ( NumberFormatException ignore ) { } } if ( getRequestScheme ( ) . equals ( "https" ) ) { return 443 ; } else if ( getRequestScheme ( ) . equals ( "http" ) ) { return 80 ; } } return getDestinationAddress ( ) . getPort ( ) ; }
Return the port that this request was sent to . In general this will be the value of the Host header minus the host name .