You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2006/01/10 23:37:54 UTC

svn commit: r367818 - in /tomcat/connectors/trunk/coyote/src/java/org/apache/coyote: Response.java tomcat4/CoyoteResponse.java

Author: markt
Date: Tue Jan 10 14:37:51 2006
New Revision: 367818

URL: http://svn.apache.org/viewcvs?rev=367818&view=rev
Log:
Alternative patch for bug 29214 based on Remy's comments

Modified:
    tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/Response.java
    tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java

Modified: tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/Response.java
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/Response.java?rev=367818&r1=367817&r2=367818&view=diff
==============================================================================
--- tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/Response.java (original)
+++ tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/Response.java Tue Jan 10 14:37:51 2006
@@ -117,16 +117,6 @@
     protected boolean charsetSet = false;
 
     /**
-     * Has the content length been explicitly set.
-     */
-    protected boolean contentLengthSet = false;
-    
-    /**
-     * Has the content type been explicitly set.
-     */
-    protected boolean contentTypeSet = false;
-    
-    /**
      * Request error URI.
      */
     protected String errorURI = null;
@@ -292,9 +282,6 @@
         characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
         contentLength = -1;
         charsetSet = false;
-        contentTypeSet = false;
-        contentLengthSet = false;
-        
 
         status = 200;
         message = null;
@@ -324,15 +311,11 @@
 
 
     // -------------------- Headers --------------------
+    /**
+     * Warning: This method always returns <code>false<code> for Content-Type
+     * and Content-Length.
+     */
     public boolean containsHeader(String name) {
-        char cc=name.charAt(0);
-        if(cc=='C' || cc=='c') {
-            if(name.equalsIgnoreCase("Content-Type")) {
-                return contentTypeSet;
-            } else if(name.equalsIgnoreCase("Content-Length")) {
-                return contentLengthSet;
-            }
-        }
         return headers.getHeader(name) != null;
     }
 
@@ -382,7 +365,6 @@
         }
         if( name.equalsIgnoreCase( "Content-Language" ) ) {
             // XXX XXX Need to construct Locale or something else
-            // Needs special handling in containsHeader() as well
         }
         return false;
     }
@@ -476,12 +458,9 @@
 
         if (type == null) {
             this.contentType = null;
-            contentTypeSet = false;
             return;
         }
 
-        contentTypeSet = true;
-
         /*
          * Remove the charset param (if any) from the Content-Type, and use it
          * to set the response encoding.
@@ -551,12 +530,10 @@
     
     public void setContentLength(int contentLength) {
         this.contentLength = contentLength;
-        contentLengthSet = true;
     }
 
     public void setContentLength(long contentLength) {
         this.contentLength = contentLength;
-        contentLengthSet = true;
     }
 
     public int getContentLength() {
@@ -592,8 +569,6 @@
         locale = DEFAULT_LOCALE;
         characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
         charsetSet = false;
-        contentLengthSet = false;
-        contentTypeSet = false;
         contentLength = -1;
         status = 200;
         message = null;

Modified: tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java?rev=367818&r1=367817&r2=367818&view=diff
==============================================================================
--- tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java (original)
+++ tomcat/connectors/trunk/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java Tue Jan 10 14:37:51 2006
@@ -235,6 +235,12 @@
      */
     protected CharChunk redirectURLCC = new CharChunk();
 
+    
+    /**
+     * Has the Content-Length header been explicitly set.
+     */
+    protected boolean contentLengthSet = false;
+    
 
     // --------------------------------------------------------- Public Methods
 
@@ -260,6 +266,7 @@
 
         writer.recycle();
 
+        contentLengthSet = false;
     }
 
 
@@ -579,6 +586,7 @@
 
         coyoteResponse.reset();
         outputBuffer.reset();
+        contentLengthSet = false;
 
     }
 
@@ -635,6 +643,8 @@
 
         coyoteResponse.setContentLength(length);
 
+        contentLengthSet = true;
+
     }
 
 
@@ -848,6 +858,13 @@
 
         coyoteResponse.addHeader(name, value);
 
+        char cc=name.charAt(0);
+        if(cc=='C' || cc=='c') {
+            if(name.equalsIgnoreCase("Content-Length")) {
+                contentLengthSet = true;
+            }
+        }
+
     }
 
 
@@ -877,6 +894,20 @@
      * @param name Name of the header to check
      */
     public boolean containsHeader(String name) {
+        // Need special handling for Content-Type and Content-Length due to
+        // special handling of these in coyoteResponse
+        char cc=name.charAt(0);
+        if(cc=='C' || cc=='c') {
+            if(name.equalsIgnoreCase("Content-Type")) {
+                // Will return null if this has not been set
+                return (coyoteResponse.getContentType() != null);
+            }
+            if(name.equalsIgnoreCase("Content-Length")) {
+                // Can't use null test since this header is an int
+                return contentLengthSet;
+            }
+        }
+
         return coyoteResponse.containsHeader(name);
     }
 
@@ -1099,6 +1130,13 @@
 
         coyoteResponse.setHeader(name, value);
 
+        char cc=name.charAt(0);
+        if(cc=='C' || cc=='c') {
+            if(name.equalsIgnoreCase("Content-Length")) {
+                contentLengthSet = true;
+            }
+        }
+
     }
 
 
@@ -1260,8 +1298,6 @@
                 return location;
 
         } catch (MalformedURLException e1) {
-            HttpServletRequest hreq =
-                (HttpServletRequest) request.getRequest();
             String requrl = request.getRequestURL().toString();
             try {
                 url = new URL(new URL(requrl), location);



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