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 2015/11/11 16:19:25 UTC

svn commit: r1713869 - /tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java

Author: markt
Date: Wed Nov 11 15:19:25 2015
New Revision: 1713869

URL: http://svn.apache.org/viewvc?rev=1713869&view=rev
Log:
Add Content-Type, Content-Language and Date headers to HTTP/2 responses

Modified:
    tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java

Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java?rev=1713869&r1=1713868&r2=1713869&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java Wed Nov 11 15:19:25 2015
@@ -47,6 +47,7 @@ import org.apache.coyote.http2.Http2Pars
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.codec.binary.Base64;
+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.SSLSupport;
@@ -485,9 +486,9 @@ public class Http2UpgradeHandler extends
             log.debug(sm.getString("upgradeHandler.writeHeaders", connectionId,
                     stream.getIdentifier()));
         }
-        MimeHeaders headers = coyoteResponse.getMimeHeaders();
-        // Add the pseudo header for status
-        headers.addValue(":status").setString(Integer.toString(coyoteResponse.getStatus()));
+
+        prepareHeaders(coyoteResponse);
+
         // This ensures the Stream processing thread has control of the socket.
         synchronized (socketWrapper) {
             byte[] header = new byte[9];
@@ -525,6 +526,32 @@ public class Http2UpgradeHandler extends
         }
     }
 
+
+    private 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 the application has already set one
+        if (headers.getValue("date") == null) {
+            headers.setValue("date").setString(FastHttpDateFormat.getCurrentDate());
+        }
+    }
+
 
     void writePushHeaders(Stream stream, int pushedStreamId, Request coyoteRequest, int payloadSize)
             throws IOException {



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