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 Http11Processor.java
Date Mon, 13 Sep 2004 21:39:40 GMT
remm        2004/09/13 14:39:40

  Modified:    http11/src/java/org/apache/coyote/http11
                        Http11Processor.java
  Log:
  - Cleanup a little access to the headers using a local variable.
  - Use direct access to the headers whenever possible (extra checks were done in Response).
  - Use setValue for Server and Date headers.
  
  Revision  Changes    Path
  1.109     +25 -33    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.108
  retrieving revision 1.109
  diff -u -r1.108 -r1.109
  --- Http11Processor.java	13 Sep 2004 18:25:08 -0000	1.108
  +++ Http11Processor.java	13 Sep 2004 21:39:39 -0000	1.109
  @@ -1126,9 +1126,10 @@
               methodMB.setString(Constants.POST);
           }
   
  +        MimeHeaders headers = request.getMimeHeaders();
  +        
           // Check connection header
  -        MessageBytes connectionValueMB = 
  -            request.getMimeHeaders().getValue("connection");
  +        MessageBytes connectionValueMB = headers.getValue("connection");
           if (connectionValueMB != null) {
               ByteChunk connectionValueBC = connectionValueMB.getByteChunk();
               if (findBytes(connectionValueBC, Constants.CLOSE_BYTES) != -1) {
  @@ -1141,7 +1142,7 @@
   
           MessageBytes expectMB = null;
           if (http11)
  -            expectMB = request.getMimeHeaders().getValue("expect");
  +            expectMB = headers.getValue("expect");
           if ((expectMB != null)
               && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) {
               inputBuffer.setSwallowInput(false);
  @@ -1150,8 +1151,7 @@
   
           // Check user-agent header
           if ((restrictedUserAgents != null) && ((http11) || (keepAlive))) {
  -            MessageBytes userAgentValueMB =  
  -                request.getMimeHeaders().getValue("user-agent");
  +            MessageBytes userAgentValueMB = headers.getValue("user-agent");
               // Check in the restricted list, and adjust the http11 
               // and keepAlive flags accordingly
               if(userAgentValueMB != null) {
  @@ -1186,8 +1186,7 @@
                           (uriB, uriBCStart + slashPos, 
                            uriBC.getLength() - slashPos);
                   }
  -                MessageBytes hostMB = 
  -                    request.getMimeHeaders().setValue("host");
  +                MessageBytes hostMB = headers.setValue("host");
                   hostMB.setBytes(uriB, uriBCStart + pos + 3, 
                                   slashPos - pos - 3);
               }
  @@ -1208,8 +1207,7 @@
           // Parse transfer-encoding header
           MessageBytes transferEncodingValueMB = null;
           if (http11)
  -            transferEncodingValueMB = 
  -                request.getMimeHeaders().getValue("transfer-encoding");
  +            transferEncodingValueMB = headers.getValue("transfer-encoding");
           if (transferEncodingValueMB != null) {
               String transferEncodingValue = transferEncodingValueMB.toString();
               // Parse the comma separated list. "identity" codings are ignored
  @@ -1238,7 +1236,7 @@
               }
           }
   
  -        MessageBytes valueMB = request.getMimeHeaders().getValue("host");
  +        MessageBytes valueMB = headers.getValue("host");
   
           // Check host header
           if (http11 && (valueMB == null)) {
  @@ -1467,8 +1465,7 @@
   
           int contentLength = response.getContentLength();
           if (contentLength != -1) {
  -            response.getMimeHeaders().setValue("Content-Length")
  -                .setInt(contentLength);
  +            headers.setValue("Content-Length").setInt(contentLength);
               outputBuffer.addActiveFilter
                   (outputFilters[Constants.IDENTITY_FILTER]);
               contentDelimitation = true;
  @@ -1477,7 +1474,7 @@
                   outputBuffer.addActiveFilter
                       (outputFilters[Constants.CHUNKED_FILTER]);
                   contentDelimitation = true;
  -                response.addHeader("Transfer-Encoding", "chunked");
  +                headers.addValue("Transfer-Encoding").setString("chunked");
               } else {
                   outputBuffer.addActiveFilter
                       (outputFilters[Constants.IDENTITY_FILTER]);
  @@ -1486,35 +1483,30 @@
   
           if (useCompression) {
               outputBuffer.addActiveFilter(outputFilters[Constants.GZIP_FILTER]);
  -            // FIXME: Make content-encoding generation dynamic
  -            response.setHeader("Content-Encoding", "gzip");
  +            headers.setValue("Content-Encoding").setString("gzip");
               // Make Proxies happy via Vary (from mod_deflate)
  -            response.setHeader("Vary", "Accept-Encoding");
  +            headers.setValue("Vary").setString("Accept-Encoding");
           }
   
           // Add date header
  -        if (! response.containsHeader("Date")){
  -          
  -          String date = null;
  -          if (System.getSecurityManager() != null){
  +        String date = null;
  +        if (System.getSecurityManager() != null){
               date = (String)AccessController.doPrivileged( 
  -                new PrivilegedAction() {
  -                    public Object run(){
  -                        return FastHttpDateFormat.getCurrentDate();
  +                    new PrivilegedAction() {
  +                        public Object run(){
  +                            return FastHttpDateFormat.getCurrentDate();
  +                        }
                       }
  -                }
               );
  -          } else {
  +        } else {
               date = FastHttpDateFormat.getCurrentDate();
  -          }
  -          response.addHeader("Date", date);
           }
  -         
  +        headers.setValue("Date").setString(date);
  +
           // Add server header
  -        response.addHeader("Server", Constants.SERVER);
  +        headers.setValue("Server").setString(Constants.SERVER);
   
  -        // Add transfer encoding header
  -        // FIXME
  +        // FIXME: Add transfer encoding header
   
           if ((entityBody) && (!contentDelimitation)) {
               // Mark as close the connection after the request, and add the 
  @@ -1526,9 +1518,9 @@
           // Connection: close header.
           keepAlive = keepAlive && !statusDropsConnection(statusCode);
           if (!keepAlive) {
  -            response.addHeader("Connection", "close");
  +            headers.addValue("Connection").setString("close");
           } else if (!http11) {
  -            response.addHeader("Connection", "Keep-Alive");
  +            headers.addValue("Connection").setString("Keep-Alive");
           }
   
           // Build the response header
  
  
  

---------------------------------------------------------------------
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