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/10/15 15:57:11 UTC

svn commit: r1708822 - in /tomcat/trunk/java: javax/servlet/http/PushBuilder.java org/apache/catalina/core/ApplicationPushBuilder.java

Author: markt
Date: Thu Oct 15 13:57:10 2015
New Revision: 1708822

URL: http://svn.apache.org/viewvc?rev=1708822&view=rev
Log:
Servlet 4.0
Progress the PushBuilder implementation (not yet complete)
Filter headers from baseRequest and copy them to the push request
Collect necessary session info from base request
Handle query string
Add basic outline for session and conditional handling
Add placeholder for %nn decoding of provided path

Modified:
    tomcat/trunk/java/javax/servlet/http/PushBuilder.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java

Modified: tomcat/trunk/java/javax/servlet/http/PushBuilder.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/http/PushBuilder.java?rev=1708822&r1=1708821&r2=1708822&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/http/PushBuilder.java (original)
+++ tomcat/trunk/java/javax/servlet/http/PushBuilder.java Thu Oct 15 13:57:10 2015
@@ -23,9 +23,11 @@ import java.util.Set;
  * builder was obtained. The push request will be constructed on the following
  * basis:
  * <ul>
- * <li>The request method is set to <code>GET</code></li>
+ * <li>The request method is set to <code>GET</code>.</li>
  * <li>The path will not be set. This must be set explicitly via a call to
- *     {@link #path(String)}</li>
+ *     {@link #path(String)}.</li>
+ * <li>Conditional, range, expectation, authorization and referer headers will
+ *     be removed.</li>
  * </ul>
  *
  * @since Servlet 4.0

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java?rev=1708822&r1=1708821&r2=1708822&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java Thu Oct 15 13:57:10 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.catalina.core;
 
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -25,11 +27,14 @@ import java.util.Set;
 
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletRequestWrapper;
+import javax.servlet.SessionTrackingMode;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
 import javax.servlet.http.PushBuilder;
 
 import org.apache.catalina.connector.Request;
 import org.apache.coyote.ActionCode;
+import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.collections.CaseInsensitiveKeyMap;
 import org.apache.tomcat.util.res.StringManager;
 
@@ -47,6 +52,8 @@ public class ApplicationPushBuilder impl
     private String lastModified;
     private String queryString;
     private String sessionId;
+    private boolean addSessionCookie;
+    private boolean addSessionPathParameter;
     private boolean conditional;
 
     public ApplicationPushBuilder(HttpServletRequest request) {
@@ -64,8 +71,6 @@ public class ApplicationPushBuilder impl
         }
 
         // Populate the initial list of HTTP headers
-        // TODO Servlet 4.0
-        //      Filter headers as required by Servlet spec
         Enumeration<String> headerNames = request.getHeaderNames();
         while (headerNames.hasMoreElements()) {
             String headerName = headerNames.nextElement();
@@ -76,6 +81,33 @@ public class ApplicationPushBuilder impl
                 values.add(headerValues.nextElement());
             }
         }
+
+        // Remove the headers
+        headers.remove("if-match");
+        headers.remove("if-none-match");
+        headers.remove("if-modified-since");
+        headers.remove("if-unmodified-since");
+        headers.remove("if-range");
+        headers.remove("range");
+        headers.remove("expect");
+        headers.remove("authorization");
+        headers.remove("referer");
+
+        HttpSession session = request.getSession(false);
+        if (session != null) {
+            sessionId = session.getId();
+        }
+        if (sessionId == null) {
+            sessionId = request.getRequestedSessionId();
+        }
+        addSessionCookie = request.isRequestedSessionIdFromCookie();
+        addSessionPathParameter = request.isRequestedSessionIdFromURL();
+        if (!addSessionCookie && !addSessionPathParameter && sessionId != null) {
+            Set<SessionTrackingMode> sessionTrackingModes =
+                    request.getServletContext().getEffectiveSessionTrackingModes();
+            addSessionCookie = sessionTrackingModes.contains(SessionTrackingMode.COOKIE);
+            addSessionPathParameter = sessionTrackingModes.contains(SessionTrackingMode.URL);
+        }
     }
 
 
@@ -247,13 +279,53 @@ public class ApplicationPushBuilder impl
         pushTarget.setServerPort(baseRequest.getServerPort());
         pushTarget.scheme().setString(baseRequest.getScheme());
 
-        pushTarget.requestURI().setString(path);
-        pushTarget.decodedURI().setString(path);
+        // Copy headers
+        for (Map.Entry<String,List<String>> header : headers.entrySet()) {
+            for (String value : header.getValue()) {
+                pushTarget.getMimeHeaders().addValue(header.getKey()).setString(value);
+            }
+        }
+
+        // Path and query string
+        int queryIndex = path.indexOf('?');
+        String pushPath;
+        String pushQueryString = null;
+        if (queryIndex > -1) {
+            pushPath = path.substring(0, queryIndex);
+            if (queryIndex + 1 < path.length()) {
+                pushQueryString = path.substring(queryIndex + 1);
+            }
+        } else {
+            pushPath = path;
+        }
+
+        // Session ID (do this before setting the path since it may change it)
+        if (sessionId != null) {
+            if (addSessionPathParameter) {
+                // TODO: Update pushPath for client's benefit
+                // TODO: Figure out how to get this into the CoyoteRequest
+            }
+            if (addSessionCookie) {
+                // TODO: add this
+            }
+        }
 
-        // TODO Copy headers
-        // TODO Implement other required attributes
-        // TODO Copy across / set other required attributes
-        // TODO Conditional request processing
+        // Undecoded path - just %nn encoded
+        pushTarget.requestURI().setString(pushPath);
+        pushTarget.decodedURI().setString(decode(pushPath, baseRequest.getCharacterEncoding()));
+
+        // Query string
+        if (pushQueryString == null && queryString != null) {
+            pushTarget.queryString().setString(queryString);
+        } else if (pushQueryString != null && queryString == null) {
+            pushTarget.queryString().setString(pushQueryString);
+        } else if (pushQueryString != null && queryString != null) {
+            pushTarget.queryString().setString(pushQueryString + "&" +queryString);
+        }
+
+        if (conditional) {
+            // TODO conditional
+        }
 
         coyoteRequest.action(ActionCode.PUSH_REQUEST, pushTarget);
 
@@ -261,5 +333,21 @@ public class ApplicationPushBuilder impl
         pushTarget = null;
         path = null;
         etag = null;
+        lastModified = null;
+    }
+
+
+    private static String decode(String input, String charsetName) {
+        Charset charset;
+        try {
+            charset = B2CConverter.getCharset(charsetName);
+        } catch (UnsupportedEncodingException uee) {
+            // Impossible since original request would have triggered an error
+            // before reaching here
+            throw new IllegalStateException(uee);
+        }
+
+        // TODO implement %nn decoding
+        return input;
     }
 }



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