Mantis - Resin
Viewing Issue Advanced Details
1509 major always 12-13-06 15:19 01-02-07 11:34
justinwcs  
ferg  
normal  
closed 3.0.22  
fixed  
none    
none 3.0.23  
0001509: getServerPort() returns incorrect number

Found a bug in getServerPort(). If you have a host like "localhost:8091" getServerPort() will say your host is 61419 because of this code in the com.caucho.server.connection.AbstractHttpRequest getServerPort() method. This is in 3.0.22.

      int length = host.length();
      int port = 0;

      for (int i = p1 + 1; i < length; i++) {
    char ch = host.charAt(i);

    if ('0' <= ch && ch <= '9')
      port = 10 * port + ch;
      }



  /**
   * Returns the server's port.
   */
  public int getServerPort()
  {
    String host = _conn.getVirtualHost();
    
    CharSequence rawHost;
    if (host == null && (rawHost = getHost()) != null) {
      int length = rawHost.length();
      int i;

      for (i = length - 1; i >= 0; i--) {
    if (rawHost.charAt(i) == ':') {
      int port = 0;

      for (i++; i < length; i++) {
        char ch = rawHost.charAt(i);

        if ('0' <= ch && ch <= '9')
          port = 10 * port + ch - '0';
      }

      return port;
    }
      }
      
      return isSecure() ? 443 : 80;
    }

    if (host == null)
      return _conn.getLocalPort();

    int p1 = host.lastIndexOf(':');
    if (p1 < 0)
      return isSecure() ? 443 : 80;
    else {
      int length = host.length();
      int port = 0;

      for (int i = p1 + 1; i < length; i++) {
    char ch = host.charAt(i);

    if ('0' <= ch && ch <= '9')
      port = 10 * port + ch;
      }

      return port;
    }
  }
This bug prevents both the Cactus and Acegi security from doing redirects properly.

Notes
(0001689)
ferg   
01-02-07 11:34   
server/052z