funkman 2003/09/21 08:25:41
Modified: coyote/src/java/org/apache/coyote Tag: coyote_10
Constants.java Response.java
Log:
Fix BZ 18092. If content type not set, don't set it with a default. Per
the spec "SRV.5.2 Headers"
(Very similar to the fix in 5 which was 18202)
Revision Changes Path
No revision
No revision
1.2.2.1 +6 -9
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Constants.java
Index: Constants.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Constants.java,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- Constants.java 8 Apr 2002 22:49:52 -0000 1.2
+++ Constants.java 21 Sep 2003 15:25:41 -0000 1.2.2.1
@@ -3,7 +3,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -11,7 +11,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -19,15 +19,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
@@ -55,7 +55,7 @@
*
* [Additional notices, if required by prior licensing conditions]
*
- */
+ */
package org.apache.coyote;
import java.util.Locale;
@@ -69,9 +69,6 @@
// -------------------------------------------------------------- Constants
-
-
- public static final String DEFAULT_CONTENT_TYPE = "text/plain";
public static final String DEFAULT_CHARACTER_ENCODING="ISO-8859-1";
1.19.2.1 +40 -38
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java
Index: Response.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java,v
retrieving revision 1.19
retrieving revision 1.19.2.1
diff -u -r1.19 -r1.19.2.1
--- Response.java 3 Dec 2002 16:37:59 -0000 1.19
+++ Response.java 21 Sep 2003 15:25:41 -0000 1.19.2.1
@@ -65,14 +65,13 @@
import org.apache.tomcat.util.buf.ByteChunk;
-import org.apache.tomcat.util.res.StringManager;
-
import org.apache.tomcat.util.http.MimeHeaders;
import org.apache.tomcat.util.http.ContentType;
+
/**
* Response object.
- *
+ *
* @author James Duncan Davidson [EMAIL PROTECTED]
* @author Jason Hunter [EMAIL PROTECTED]
* @author James Todd [EMAIL PROTECTED]
@@ -91,14 +90,14 @@
// ----------------------------------------------------- Instance Variables
-
-
+
+
/**
* Default locale as mandated by the spec.
*/
private static Locale DEFAULT_LOCALE = new Locale("en", "US");
-
-
+
+
/**
* Status code.
*/
@@ -144,7 +143,7 @@
/**
* HTTP specific fields.
*/
- protected String contentType = Constants.DEFAULT_CONTENT_TYPE;
+ protected String contentType = null;
protected String contentLanguage = null;
protected String characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
protected int contentLength = -1;
@@ -216,7 +215,7 @@
public void action(ActionCode actionCode, Object param) {
if (hook != null) {
- if( param==null )
+ if( param==null )
hook.action(actionCode, this);
else
hook.action(actionCode, param);
@@ -231,10 +230,10 @@
return status;
}
-
- /**
- * Set the response status
- */
+
+ /**
+ * Set the response status
+ */
public void setStatus( int status ) {
this.status = status;
}
@@ -269,7 +268,7 @@
// -----------------Error State --------------------
- /**
+ /**
* Set the error Exception that occurred during
* request processing.
*/
@@ -278,7 +277,7 @@
}
- /**
+ /**
* Get the Exception that occurred during request
* processing.
*/
@@ -292,7 +291,7 @@
}
- /**
+ /**
* Set request URI that caused an error during
* request processing.
*/
@@ -309,14 +308,14 @@
// -------------------- Methods --------------------
-
-
- public void reset()
+
+
+ public void reset()
throws IllegalStateException {
-
+
// Reset the headers only if this is the main request,
// not for included
- contentType = Constants.DEFAULT_CONTENT_TYPE;
+ contentType = null;
locale = DEFAULT_LOCALE;
contentLanguage = null;
characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
@@ -325,16 +324,16 @@
status = 200;
message = null;
headers.clear();
-
+
// Force the PrintWriter to flush its data to the output
// stream before resetting the output stream
//
// Reset the stream
if (commited) {
- //String msg = sm.getString("servletOutputStreamImpl.reset.ise");
+ //String msg = sm.getString("servletOutputStreamImpl.reset.ise");
throw new IllegalStateException();
}
-
+
action(ActionCode.ACTION_RESET, this);
}
@@ -374,9 +373,9 @@
headers.addValue(name).setString( value );
}
-
- /**
- * Set internal fields for special header names.
+
+ /**
+ * Set internal fields for special header names.
* Called from set/addHeader.
* Return true if the header is special, no need to set the header.
*/
@@ -393,7 +392,7 @@
setContentLength( cL );
return true;
} catch( NumberFormatException ex ) {
- // Do nothing - the spec doesn't have any "throws"
+ // Do nothing - the spec doesn't have any "throws"
// and the user might know what he's doing
return false;
}
@@ -468,14 +467,17 @@
if (isCommitted())
return;
+ if (charset == null || this.contentType==null)
+ return;
+
String type = this.contentType;
int start = type.indexOf("charset=");
if ( start != -1 ) {
int end = type.indexOf(';', start+8);
- if (end >= 0)
+ if (end >= 0)
type = type.substring(0,start+8)
+charset+type.substring(end-1);
- else
+ else
type = type.substring(0,start+8)
+charset;
this.contentType = type;
@@ -485,10 +487,10 @@
type = type.substring(0, end) + ";charset=" + charset;
} else {
type = type + ";charset=" + charset;
- }
+ }
}
setContentType( type );
-
+
}
public String getCharacterEncoding() {
@@ -506,7 +508,7 @@
public String getContentType() {
return contentType;
}
-
+
public void setContentLength(int contentLength) {
this.contentLength = contentLength;
}
@@ -516,7 +518,7 @@
}
- /**
+ /**
* Write a chunk of bytes.
*/
public void doWrite(ByteChunk chunk/*byte buffer[], int pos, int count*/)
@@ -526,10 +528,10 @@
// --------------------
-
+
public void recycle() {
-
- contentType = Constants.DEFAULT_CONTENT_TYPE;
+
+ contentType = null;
contentLanguage = null;
locale = DEFAULT_LOCALE;
characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
@@ -540,7 +542,7 @@
errorException = null;
errorURI = null;
headers.clear();
-
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]