tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11 Constants.java Http11Processor.java Http11Protocol.java
Date Wed, 29 Sep 2004 09:54:28 GMT
remm        2004/09/29 02:54:28

  Modified:    http11/src/java/org/apache/coyote/http11 Constants.java
                        Http11Processor.java Http11Protocol.java
  Log:
  - Add a utility method to convert strings to byte arrays.
  - Add a few additional byte arrays.
  
  Revision  Changes    Path
  1.23      +27 -74    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Constants.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Constants.java	24 Feb 2004 08:50:56 -0000	1.22
  +++ Constants.java	29 Sep 2004 09:54:28 -0000	1.23
  @@ -39,12 +39,13 @@
       public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 0;
       public static final boolean DEFAULT_TCP_NO_DELAY = true;
       
  +    
       /**
        * Server string.
        */
  -    public static final String SERVER = "Apache-Coyote/1.1";
  -
  +    public static final byte[] SERVER_BYTES = convertToBytes("Apache-Coyote/1.1");
   
  +    
       /**
        * CR.
        */
  @@ -116,47 +117,17 @@
        */
       public static final String CRLF = "\r\n";
   
  -
  -    /**
  -     * CRLF bytes.
  -     */
  -    public static final byte[] CRLF_BYTES = {(byte) '\r', (byte) '\n'};
  -
  -
  -    /**
  -     * Colon bytes.
  -     */
  -    public static final byte[] COLON_BYTES = {(byte) ':', (byte) ' '};
  -
  -
  -    /**
  -     * Close bytes.
  -     */
  -    public static final byte[] CLOSE_BYTES = {
  -        (byte) 'c',
  -        (byte) 'l',
  -        (byte) 'o',
  -        (byte) 's',
  -        (byte) 'e'
  -    };
  -
  -
  -    /**
  -     * Keep-alive bytes.
  -     */
  -    public static final byte[] KEEPALIVE_BYTES = {
  -        (byte) 'k',
  -        (byte) 'e',
  -        (byte) 'e',
  -        (byte) 'p',
  -        (byte) '-',
  -        (byte) 'a',
  -        (byte) 'l',
  -        (byte) 'i',
  -        (byte) 'v',
  -        (byte) 'e'
  -    };
  -
  +    
  +    /* Various constant "strings" */
  +    public static final byte[] CRLF_BYTES = convertToBytes(CRLF);
  +    public static final byte[] COLON_BYTES = convertToBytes(": ");
  +    public static final byte[] CONNECTION_BYTES = convertToBytes("Connection");
  +    public static final byte[] CLOSE_BYTES = convertToBytes("close");
  +    public static final byte[] KEEPALIVE_BYTES = convertToBytes("keep-alive");
  +    public static final byte[] CHUNKED_BYTES = convertToBytes("chunked");
  +    public static final byte[] ACK_BYTES = convertToBytes("HTTP/1.1 100 Continue" + CRLF
+ CRLF);
  +    public static final byte[] TRANSFERENCODING_BYTES = convertToBytes("Transfer-Encoding");
  +    
   
       /**
        * Identity filters (input and output).
  @@ -219,35 +190,17 @@
   
   
       /**
  -     * Ack string when pipelining HTTP requests.
  -     */
  -    public static final byte[] ACK_BYTES = {
  -        (byte) 'H',
  -        (byte) 'T',
  -        (byte) 'T',
  -        (byte) 'P',
  -        (byte) '/',
  -        (byte) '1',
  -        (byte) '.',
  -        (byte) '1',
  -        (byte) ' ',
  -        (byte) '1',
  -        (byte) '0',
  -        (byte) '0',
  -        (byte) ' ',
  -        (byte) 'C',
  -        (byte) 'o',
  -        (byte) 'n',
  -        (byte) 't',
  -        (byte) 'i',
  -        (byte) 'n',
  -        (byte) 'u',
  -        (byte) 'e',
  -        (byte) '\r',
  -        (byte) '\n',
  -        (byte) '\r',
  -        (byte) '\n'
  -    };
  -
  -
  +     * Utility method.
  +     * 
  +     * @param value to convert to byte array
  +     * @return the byte array value
  +     */
  +    public static final byte[] convertToBytes(String value) {
  +        byte[] result = new byte[value.length()];
  +        for (int i = 0; i < value.length(); i++) {
  +            result[i] = (byte) value.charAt(i);
  +        }
  +        return result;
  +    }
  +    
   }
  
  
  
  1.111     +15 -6     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java
  
  Index: Http11Processor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v
  retrieving revision 1.110
  retrieving revision 1.111
  diff -u -r1.110 -r1.111
  --- Http11Processor.java	15 Sep 2004 00:16:05 -0000	1.110
  +++ Http11Processor.java	29 Sep 2004 09:54:28 -0000	1.111
  @@ -300,7 +300,7 @@
       /**
        * Allow a customized the server header for the tin-foil hat folks.
        */
  -    protected String server = Constants.SERVER;
  +    protected String server = null;
   
   
       // ------------------------------------------------------------- Properties
  @@ -708,7 +708,7 @@
        */
       public void setServer( String server ) {
           if (server==null || server.equals("")) {
  -            this.server = Constants.SERVER;
  +            this.server = null;
           } else {
               this.server = server;
           }
  @@ -1500,7 +1500,9 @@
                   outputBuffer.addActiveFilter
                       (outputFilters[Constants.CHUNKED_FILTER]);
                   contentDelimitation = true;
  -                headers.addValue("Transfer-Encoding").setString("chunked");
  +                headers.addValue(Constants.TRANSFERENCODING_BYTES, 
  +                        0, Constants.TRANSFERENCODING_BYTES.length).setBytes
  +                    (Constants.CHUNKED_BYTES, 0, Constants.CHUNKED_BYTES.length);
               } else {
                   outputBuffer.addActiveFilter
                       (outputFilters[Constants.IDENTITY_FILTER]);
  @@ -1530,7 +1532,12 @@
           headers.setValue("Date").setString(date);
   
           // Add server header
  -        headers.setValue("Server").setString(server);
  +        if (server != null) {
  +            headers.setValue("Server").setString(server);
  +        } else {
  +            headers.setValue("Server").setBytes(Constants.SERVER_BYTES, 
  +                    0, Constants.SERVER_BYTES.length);
  +        }
   
           // FIXME: Add transfer encoding header
   
  @@ -1544,9 +1551,11 @@
           // Connection: close header.
           keepAlive = keepAlive && !statusDropsConnection(statusCode);
           if (!keepAlive) {
  -            headers.addValue("Connection").setString("close");
  +            headers.addValue(Constants.CONNECTION_BYTES, 0, Constants.CONNECTION_BYTES.length)
  +                .setBytes(Constants.CLOSE_BYTES, 0, Constants.CLOSE_BYTES.length);
           } else if (!http11) {
  -            headers.addValue("Connection").setString("Keep-Alive");
  +            headers.addValue(Constants.CONNECTION_BYTES, 0, Constants.CONNECTION_BYTES.length)
  +                .setBytes(Constants.KEEPALIVE_BYTES, 0, Constants.KEEPALIVE_BYTES.length);
           }
   
           // Build the response header
  
  
  
  1.57      +38 -33    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java
  
  Index: Http11Protocol.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- Http11Protocol.java	15 Sep 2004 00:16:05 -0000	1.56
  +++ Http11Protocol.java	29 Sep 2004 09:54:28 -0000	1.57
  @@ -115,7 +115,7 @@
        */
       public void init() throws Exception {
           ep.setConnectionHandler( cHandler );
  -    try {
  +        try {
               checkSocketFactory();
           } catch( Exception ex ) {
               log.error(sm.getString("http11protocol.socketfactory.initerror"),
  @@ -128,7 +128,8 @@
               while( attE.hasMoreElements() ) {
                   String key=(String)attE.nextElement();
                   Object v=attributes.get( key );
  -                socketFactory.setAttribute( key, v );
  +                String trnName = translateAttributeName(key);
  +                socketFactory.setAttribute( trnName, v );
               }
           }
   
  @@ -304,7 +305,6 @@
       public void setPort( int port ) {
           ep.setPort(port);
           setAttribute("port", "" + port);
  -        //this.port=port;
       }
   
       public InetAddress getAddress() {
  @@ -327,12 +327,6 @@
           return ("http-" + encodedAddr + ep.getPort());
       }
   
  -    // commenting out for now since it's not doing anything
  -    //public void setHostName( String name ) {
  -    // ??? Doesn't seem to be used in existing or prev code
  -    // vhost=name;
  -    //}
  -
       public String getSocketFactory() {
           return socketFactoryName;
       }
  @@ -559,6 +553,22 @@
           setAttribute("maxKeepAliveRequests", "" + mkar);
       }
   
  +    /**
  +     * Return the Keep-Alive policy for the connection.
  +     */
  +    public boolean getKeepAlive() {
  +        return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1));
  +    }
  +
  +    /**
  +     * Set the keep-alive policy for this connection.
  +     */
  +    public void setKeepAlive(boolean keepAlive) {
  +        if (!keepAlive) {
  +            setMaxKeepAliveRequests(1);
  +        }
  +    }
  +
       public int getSocketCloseDelay() {
           return socketCloseDelay;
       }
  @@ -796,31 +806,26 @@
           }
       }
   
  -    /*
  -    public boolean isKeystoreSet() {
  -        return (attributes.get("keystore") != null);
  -    }
  -
  -    public boolean isKeypassSet() {
  -        return (attributes.get("keypass") != null);
  -    }
  -
  -    public boolean isClientauthSet() {
  -        return (attributes.get("clientauth") != null);
  -    }
  -
  -    public boolean isAttributeSet( String attr ) {
  -        return (attributes.get(attr) != null);
  -    }
  -
  -    public boolean isSecure() {
  -        return secure;
  -    }
  -
  -    public PoolTcpEndpoint getEndpoint() {
  -        return ep;
  +    private String translateAttributeName(String name) {
  +        if ("clientAuth".equals(name)) {
  +            return "clientauth";
  +        } else if ("keystoreFile".equals(name)) {
  +            return "keystore";
  +        } else if ("randomFile".equals(name)) {
  +            return "randomfile";
  +        } else if ("rootFile".equals(name)) {
  +            return "rootfile";
  +        } else if ("keystorePass".equals(name)) {
  +            return "keypass";
  +        } else if ("keystoreType".equals(name)) {
  +            return "keytype";
  +        } else if ("sslProtocol".equals(name)) {
  +            return "protocol";
  +        } else if ("sslProtocols".equals(name)) {
  +            return "protocols";
  +        }
  +        return name;
       }
  -    */
   
       protected String domain;
       protected ObjectName oname;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message