Author: markt Date: Tue Nov 28 20:25:07 2017 New Revision: 1816570 URL: http://svn.apache.org/viewvc?rev=1816570&view=rev Log: Refactor header preparation with adding compression support in mind.
Modified: tomcat/trunk/java/org/apache/coyote/http2/Stream.java tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java Modified: tomcat/trunk/java/org/apache/coyote/http2/Stream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Stream.java?rev=1816570&r1=1816569&r2=1816570&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/Stream.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/Stream.java Tue Nov 28 20:25:07 2017 @@ -39,7 +39,6 @@ import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.buf.MessageBytes; -import org.apache.tomcat.util.http.FastHttpDateFormat; import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.net.ApplicationBufferHandler; import org.apache.tomcat.util.res.StringManager; @@ -59,7 +58,7 @@ class Stream extends AbstractStream impl static { Response response = new Response(); response.setStatus(100); - prepareHeaders(response); + StreamProcessor.prepareHeaders(response); ACK_HEADERS = response.getMimeHeaders(); } @@ -407,7 +406,6 @@ class Stream extends AbstractStream impl final void writeHeaders() throws IOException { - prepareHeaders(coyoteResponse); boolean endOfStream = getOutputBuffer().hasNoBody() && coyoteResponse.getTrailerFields() == null; // TODO: Is 1k the optimal value? @@ -665,33 +663,6 @@ class Stream extends AbstractStream impl } } - - private static void prepareHeaders(Response coyoteResponse) { - MimeHeaders headers = coyoteResponse.getMimeHeaders(); - int statusCode = coyoteResponse.getStatus(); - - // Add the pseudo header for status - headers.addValue(":status").setString(Integer.toString(statusCode)); - - // Check to see if a response body is present - if (!(statusCode < 200 || statusCode == 205 || statusCode == 304)) { - String contentType = coyoteResponse.getContentType(); - if (contentType != null) { - headers.setValue("content-type").setString(contentType); - } - String contentLanguage = coyoteResponse.getContentLanguage(); - if (contentLanguage != null) { - headers.setValue("content-language").setString(contentLanguage); - } - } - - // Add date header unless it is an informational response or the - // application has already set one - if (statusCode >= 200 && headers.getValue("date") == null) { - headers.addValue("date").setString(FastHttpDateFormat.getCurrentDate()); - } - } - private static class PrivilegedPush implements PrivilegedExceptionAction<Void> { Modified: tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java?rev=1816570&r1=1816569&r2=1816570&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java Tue Nov 28 20:25:07 2017 @@ -25,9 +25,12 @@ import org.apache.coyote.Adapter; import org.apache.coyote.ContainerThreadMarker; import org.apache.coyote.ErrorState; import org.apache.coyote.Request; +import org.apache.coyote.Response; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.buf.ByteChunk; +import org.apache.tomcat.util.http.FastHttpDateFormat; +import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.DispatchType; import org.apache.tomcat.util.net.SendfileState; @@ -98,10 +101,38 @@ class StreamProcessor extends AbstractPr @Override protected final void prepareResponse() throws IOException { response.setCommitted(true); + prepareHeaders(response); stream.writeHeaders(); } + static void prepareHeaders(Response coyoteResponse) { + MimeHeaders headers = coyoteResponse.getMimeHeaders(); + int statusCode = coyoteResponse.getStatus(); + + // Add the pseudo header for status + headers.addValue(":status").setString(Integer.toString(statusCode)); + + // Check to see if a response body is present + if (!(statusCode < 200 || statusCode == 205 || statusCode == 304)) { + String contentType = coyoteResponse.getContentType(); + if (contentType != null) { + headers.setValue("content-type").setString(contentType); + } + String contentLanguage = coyoteResponse.getContentLanguage(); + if (contentLanguage != null) { + headers.setValue("content-language").setString(contentLanguage); + } + } + + // Add date header unless it is an informational response or the + // application has already set one + if (statusCode >= 200 && headers.getValue("date") == null) { + headers.addValue("date").setString(FastHttpDateFormat.getCurrentDate()); + } + } + + @Override protected final void finishResponse() throws IOException { sendfileState = handler.processSendfile(stream); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org