remm        2002/10/10 06:14:56

  Modified:    http11/src/java/org/apache/coyote/http11 Constants.java
                        Http11Processor.java InternalOutputBuffer.java
  Log:
  - Optimizations: remove some String based operations.
  
  Revision  Changes    Path
  1.11      +25 -1     
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Constants.java    9 Oct 2002 16:56:17 -0000       1.10
  +++ Constants.java    10 Oct 2002 13:14:55 -0000      1.11
  @@ -157,6 +157,30 @@
   
   
       /**
  +     * CRLF bytes.
  +     */
  +    public static final byte[] CRLF_BYTES = "\r\n".getBytes();
  +
  +
  +    /**
  +     * Colon bytes.
  +     */
  +    public static final byte[] COLON_BYTES = ": ".getBytes();
  +
  +
  +    /**
  +     * Close bytes.
  +     */
  +    public static final byte[] CLOSE_BYTES = "close".getBytes();
  +
  +
  +    /**
  +     * Keep-alive bytes.
  +     */
  +    public static final byte[] KEEPALIVE_BYTES = "keep-alive".getBytes();
  +
  +
  +    /**
        * Indetity filters (input and output).
        */
       public static final int IDENTITY_FILTER = 0;
  @@ -190,7 +214,7 @@
        * Ack string when pipelining HTTP requests.
        */
       public static final byte[] ACK =
  -        (new String("HTTP/1.1 100 Continue\r\n\r\n")).getBytes();
  +        "HTTP/1.1 100 Continue\r\n\r\n".getBytes();
   
   
   }
  
  
  
  1.41      +38 -9     
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.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- Http11Processor.java      6 Oct 2002 18:10:04 -0000       1.40
  +++ Http11Processor.java      10 Oct 2002 13:14:55 -0000      1.41
  @@ -71,6 +71,7 @@
   import org.apache.tomcat.util.buf.MessageBytes;
   import org.apache.tomcat.util.http.FastHttpDateFormat;
   import org.apache.tomcat.util.http.MimeHeaders;
  +import org.apache.tomcat.util.buf.Ascii;
   import org.apache.tomcat.util.buf.HexUtils;
   import org.apache.tomcat.util.net.SSLSupport;
   
  @@ -646,22 +647,21 @@
           MessageBytes connectionValueMB = 
               request.getMimeHeaders().getValue("connection");
           if (connectionValueMB != null) {
  -            String connectionValue = 
  -                connectionValueMB.toString().toLowerCase().trim();
  -            // FIXME: This can be a comma separated list
  -            if (connectionValue.equals("close")) {
  +            ByteChunk connectionValueBC = connectionValueMB.getByteChunk();
  +            if (findBytes(connectionValueBC, Constants.CLOSE_BYTES) != -1) {
                   keepAlive = false;
  -            } else if (connectionValue.equals("keep-alive")) {
  +            } else if (findBytes(connectionValueBC, 
  +                                 Constants.KEEPALIVE_BYTES) != -1) {
                   keepAlive = true;
               }
           }
   
           // Check user-agent header
  -        MessageBytes userAgentValueMB =  
  -            request.getMimeHeaders().getValue("user-agent");
  -        // Check in the restricted list, and adjust the http11 
  -        // and keepAlive flags accordingly
           if ((restrictedUserAgents != null) && ((http11) || (keepAlive))) {
  +            MessageBytes userAgentValueMB =  
  +                request.getMimeHeaders().getValue("user-agent");
  +            // Check in the restricted list, and adjust the http11 
  +            // and keepAlive flags accordingly
               String userAgentValue = userAgentValueMB.toString();
               for (int i = 0; i < restrictedUserAgents.length; i++) {
                   if (restrictedUserAgents[i].equals(userAgentValue)) {
  @@ -969,6 +969,35 @@
               return false;
           }
           return true;
  +    }
  +
  +
  +    /**
  +     * Specialized utility method: find a sequence of lower case bytes inside
  +     * a ByteChunk.
  +     */
  +    protected int findBytes(ByteChunk bc, byte[] b) {
  +
  +        byte first = b[0];
  +        byte[] buff = bc.getBuffer();
  +        int start = bc.getStart();
  +        int end = bc.getEnd();
  +
  +     // Look for first char 
  +     int srcEnd = b.length;
  +        
  +     for (int i = start; i <= (end - srcEnd); i++) {
  +         if (buff[i] != first) continue;
  +         // found first char, now look for a match
  +            int myPos = i+1;
  +         for (int srcPos = 1; srcPos < srcEnd; ) {
  +                if (buff[myPos++] != Ascii.toLower(b[srcPos++]))
  +                 break;
  +                if (srcPos == srcEnd) return i - start; // found it
  +         }
  +     }
  +     return -1;
  +
       }
   
   
  
  
  
  1.15      +20 -4     
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java
  
  Index: InternalOutputBuffer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- InternalOutputBuffer.java 9 Apr 2002 18:35:54 -0000       1.14
  +++ InternalOutputBuffer.java 10 Oct 2002 13:14:55 -0000      1.15
  @@ -432,7 +432,7 @@
           }
   
           // End the response status line
  -        write(Constants.CRLF);
  +        write(Constants.CRLF_BYTES);
   
       }
   
  @@ -448,7 +448,7 @@
           write(name);
           write(": ");
           write(value);
  -        write(Constants.CRLF);
  +        write(Constants.CRLF_BYTES);
   
       }
   
  @@ -464,7 +464,7 @@
           write(name);
           write(": ");
           write(value);
  -        write(Constants.CRLF);
  +        write(Constants.CRLF_BYTES);
   
       }
   
  @@ -480,7 +480,7 @@
           write(name);
           write(": ");
           write(value);
  -        write(Constants.CRLF);
  +        write(Constants.CRLF_BYTES);
   
       }
   
  @@ -583,6 +583,22 @@
           System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos,
                            bc.getLength());
           pos = pos + bc.getLength();
  +
  +    }
  +
  +
  +    /**
  +     * This method will write the contents of the specyfied byte 
  +     * buffer to the output stream, without filtering. This method is meant to
  +     * be used to write the response header.
  +     * 
  +     * @param b data to be written
  +     */
  +    protected void write(byte[] b) {
  +
  +        // Writing the byte chunk to the output buffer
  +        System.arraycopy(b, 0, buf, pos, b.length);
  +        pos = pos + b.length;
   
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to