remm 00/11/09 10:52:09 Modified: catalina/src/share/org/apache/catalina/connector/http HttpResponseImpl.java HttpResponseStream.java Log: - The determination of the chunk mode flag is more dynamic. Before, it was only determined when the stream was instantiated, which could lead to problems. Revision Changes Path 1.3 +125 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpResponseImpl.java Index: HttpResponseImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpResponseImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HttpResponseImpl.java 2000/10/07 05:27:35 1.2 +++ HttpResponseImpl.java 2000/11/09 18:52:08 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpResponseImpl.java,v 1.2 2000/10/07 05:27:35 craigmcc Exp $ - * $Revision: 1.2 $ - * $Date: 2000/10/07 05:27:35 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpResponseImpl.java,v 1.3 2000/11/09 18:52:08 remm Exp $ + * $Revision: 1.3 $ + * $Date: 2000/11/09 18:52:08 $ * * ==================================================================== * @@ -68,6 +68,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.OutputStream; +import java.util.ArrayList; import javax.servlet.ServletOutputStream; import org.apache.catalina.connector.HttpResponseBase; @@ -76,7 +77,8 @@ * Implementation of <b>HttpResponse</b> specific to the HTTP connector. * * @author Craig R. McClanahan - * @version $Revision: 1.2 $ $Date: 2000/10/07 05:27:35 $ + * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> + * @version $Revision: 1.3 $ $Date: 2000/11/09 18:52:08 $ */ final class HttpResponseImpl @@ -99,6 +101,12 @@ protected boolean allowChunking; + /** + * Associated HTTP response stream. + */ + protected HttpResponseStream responseStream; + + // ------------------------------------------------------------- Properties @@ -140,6 +148,7 @@ public void recycle() { super.recycle(); + responseStream = null; allowChunking = false; } @@ -194,8 +203,119 @@ * @exception IOException if an input/output error occurs */ public ServletOutputStream createOutputStream() throws IOException { + + responseStream = new HttpResponseStream(this); + return (responseStream); + + } + + + /** + * Tests is the connection will be closed after the processing of the + * request. + */ + public boolean isCloseConnection() { + String connectionValue = (String) getHeader("Connection"); + return (connectionValue != null + && connectionValue.equals("close")); + } + + + /** + * Add the specified header to the specified value. + * + * @param name Name of the header to set + * @param value Value to be set + */ + public void addHeader(String name, String value) { + + if (isCommitted()) + return; + + if (included) + return; // Ignore any call from an included servlet + + super.addHeader(name, value); + + if (name.equals("Connection") && responseStream != null) + responseStream.checkChunking(this); + + } + + + + + /** + * Set the specified header to the specified value. + * + * @param name Name of the header to set + * @param value Value to be set + */ + public void setHeader(String name, String value) { + + if (isCommitted()) + return; + + if (included) + return; // Ignore any call from an included servlet + + super.setHeader(name, value); + + if (name.equals("Connection") && responseStream != null) + responseStream.checkChunking(this); + + } + + + /** + * Removes the specified header. + * + * @param name Name of the header to remove + * @param value Value to remove + */ + public void removeHeader(String name, String value) { + + if (isCommitted()) + return; + + if (included) + return; // Ignore any call from an included servlet + + synchronized (headers) { + ArrayList values = (ArrayList) headers.get(name); + if ((values != null) && (!values.isEmpty())) { + values.remove(value); + if (values.isEmpty()) + headers.remove(name); + } + } + + if (name.equals("Connection") && responseStream != null) + responseStream.checkChunking(this); + + } + + + // -------------------------------------------- HttpServletResponse Methods + + + /** + * Set the content length (in bytes) for this Response. + * + * @param length The new content length + */ + public void setContentLength(int length) { + + if (isCommitted()) + return; + + if (included) + return; // Ignore any call from an included servlet + + super.setContentLength(length); - return (new HttpResponseStream(this)); + if (responseStream != null) + responseStream.checkChunking(this); } 1.3 +27 -10 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpResponseStream.java Index: HttpResponseStream.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpResponseStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HttpResponseStream.java 2000/08/19 05:29:16 1.2 +++ HttpResponseStream.java 2000/11/09 18:52:08 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpResponseStream.java,v 1.2 2000/08/19 05:29:16 remm Exp $ - * $Revision: 1.2 $ - * $Date: 2000/08/19 05:29:16 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpResponseStream.java,v 1.3 2000/11/09 18:52:08 remm Exp $ + * $Revision: 1.3 $ + * $Date: 2000/11/09 18:52:08 $ * * ==================================================================== * @@ -65,6 +65,7 @@ package org.apache.catalina.connector.http; import java.io.IOException; +import javax.servlet.http.HttpServletResponse; import org.apache.catalina.Response; import org.apache.catalina.connector.ResponseStream; @@ -98,13 +99,7 @@ public HttpResponseStream(HttpResponseImpl response) { super(response); - this.useChunking = (!response.isCommitted() - && response.isChunkingAllowed() - && response.getContentLength() == -1 - && response.getStatus() != 206 - && response.getStatus() != 304); - if (this.useChunking) - response.addHeader("Transfer-Encoding", "chunked"); + checkChunking(response); } @@ -179,6 +174,28 @@ } super.close(); + } + + + // -------------------------------------------------------- Package Methods + + + void checkChunking(HttpResponseImpl response) { + // If any data has already been written to the stream, we must not + // change the chunking mode + if (count != 0) + return; + this.useChunking = + (!response.isCommitted() + && response.isChunkingAllowed() + && response.getContentLength() == -1 + && response.getStatus() != HttpServletResponse.SC_PARTIAL_CONTENT + && response.getStatus() != HttpServletResponse.SC_NOT_MODIFIED + && !response.isCloseConnection()); + if (this.useChunking) + response.addHeader("Transfer-Encoding", "chunked"); + else + response.removeHeader("Transfer-Encoding", "chunked"); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]