"Craig R. McClanahan" wrote:
>
> Jean-Michel Leon wrote:
>
> >
> > this deliberate behavior in tomcat is wrong (i.e. it's a bug), because
> > the servlet spec does not specify that servlets should override the
> > programmer's contnet-type wth its own defaults.
> >
>
> In other words, you would like the following sequence of events:
>
> <%
> response.setHeader("Content-Type", "foo/bar");
> response.setContentType("x-application/my-content-type");
> %>
>
> to result in a content type of "foo/bar", despite the fact that the programmer
> explicitly sets it? Seems to me you could make a case that this is a bug, just as
> strongly as the argument you are making.
no. and I don't understand why you're suggesting that.
> I remind you again -- in the case where the servlet spec is not speciific (it is
>silent
> on the topic you are raising regarding content type; not quite so silent on content
> length -- see the 2.2 API docs), i.e. it is an interpretation issue, the reference
> implementation defines correct behavior. And guess what the reference implementation
> here is?
Since setHeader is in the spec; it means programmers are allowed to use
it. the fact that tomcat doesn't let you use it simply means that the
reference implementation is broken. now it's a question of deciding
whether the reference implementation should be fixed, or the spec.
I say it's the reference implementation. default headers should be set
when the response object is created, so they could be overriden by the
programmer. setContenType should simply do
headers.setHeader(Content-Type), and thus would be 100% consistent with
setHeader.
I'm including the patch for this fix.
It may even compile (I'd have tried if the build system was usable).
jm.
*** Response.orig.java Mon Jan 17 07:39:24 2000
--- Response.java Mon Jan 17 07:40:50 2000
*************** public class Response {
*** 85,91 ****
protected HttpServletResponseFacade responseFacade;
protected Vector userCookies = new Vector();
protected Vector systemCookies = new Vector();
- protected String contentType = Constants.ContentType.Default;
protected String contentLanguage = null;
protected String characterEncoding =
System.getProperty("file.encoding",
--- 85,90 ----
*************** public class Response {
*** 111,116 ****
--- 110,116 ----
responseFacade = new HttpServletResponseFacade(this);
out=new BufferedServletOutputStream();
out.setResponse(this);
+ clearHeaders();
}
public void setResponseAdapter( ResponseAdapter resA ) {
*************** public class Response {
*** 156,172 ****
// BufferedServletOutputStream out) {
// this.out=out;
// }
public void recycle() {
userCookies.removeAllElements();
systemCookies.removeAllElements();
! contentType = Constants.ContentType.Default;
locale = new Locale(Constants.Locale.Default, "");
characterEncoding = System.getProperty("file.encoding",
Constants.CharacterEncoding.Default);
contentLength = -1;
status = 200;
! headers.clear();
usingWriter = false;
usingStream = false;
writer=null;
--- 156,182 ----
// BufferedServletOutputStream out) {
// this.out=out;
// }
+
+
+ /**
+ * reset the headers to their default values
+ */
+ void clearHeader() {
+ // set default headers.
+ headers.clear();
+ headers.setHeader("Content-Type", Constants.ContentType.Default);
+ }
public void recycle() {
userCookies.removeAllElements();
systemCookies.removeAllElements();
! //contentType = Constants.ContentType.Default;
locale = new Locale(Constants.Locale.Default, "");
characterEncoding = System.getProperty("file.encoding",
Constants.CharacterEncoding.Default);
contentLength = -1;
status = 200;
! clearHeader();
usingWriter = false;
usingStream = false;
writer=null;
*************** public class Response {
*** 297,303 ****
// stream before resetting the output stream
//
userCookies.removeAllElements(); // keep system (session) cookies
- contentType = Constants.ContentType.Default;
locale = new Locale(Constants.Locale.Default, "");
characterEncoding = System.getProperty("file.encoding",
Constants.CharacterEncoding.Default);
--- 307,312 ----
*************** public class Response {
*** 313,319 ****
// Clear the cookies and such
// Clear the headers
! headers.clear();
}
public void flushBuffer() throws IOException {
--- 322,328 ----
// Clear the cookies and such
// Clear the headers
! clearHeaders();
}
public void flushBuffer() throws IOException {
*************** public class Response {
*** 331,337 ****
headers.putHeader("Date", date.toString());
headers.putIntHeader("Status", status);
- headers.putHeader("Content-Type", contentType);
// Generated by Server!!!
//headers.putDateHeader("Date",System.currentTimeMillis());
--- 340,345 ----
*************** public class Response {
*** 450,456 ****
}
public void setContentType(String contentType) {
! this.contentType = contentType;
String encoding = RequestUtil.getCharsetFromContentType(contentType);
if (encoding != null) {
characterEncoding = encoding;
--- 458,464 ----
}
public void setContentType(String contentType) {
! setHeader("Content-Type", contentType);
String encoding = RequestUtil.getCharsetFromContentType(contentType);
if (encoding != null) {
characterEncoding = encoding;