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/16 12:05:38 UTC
svn commit: r1708941 -
/tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java
Author: markt
Date: Fri Oct 16 10:05:38 2015
New Revision: 1708941
URL: http://svn.apache.org/viewvc?rev=1708941&view=rev
Log:
Servlet 4.0
Complete a PushBuilder TODO - Cookies
Modified:
tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java
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=1708941&r1=1708940&r2=1708941&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java Fri Oct 16 10:05:38 2015
@@ -40,6 +40,7 @@ import org.apache.coyote.ActionCode;
import org.apache.tomcat.util.buf.B2CConverter;
import org.apache.tomcat.util.buf.HexUtils;
import org.apache.tomcat.util.collections.CaseInsensitiveKeyMap;
+import org.apache.tomcat.util.http.CookieProcessor;
import org.apache.tomcat.util.res.StringManager;
public class ApplicationPushBuilder implements PushBuilder {
@@ -385,7 +386,8 @@ public class ApplicationPushBuilder impl
}
// Cookies
- // TODO
+ setHeader("cookie", generateCookieHeader(cookies,
+ catalinaRequest.getContext().getCookieProcessor()));
coyoteRequest.action(ActionCode.PUSH_REQUEST, pushTarget);
@@ -437,6 +439,7 @@ public class ApplicationPushBuilder impl
return result.toString();
}
+
private static String decode(String percentSequence, Charset charset) {
byte[] bytes = new byte[percentSequence.length()/3];
for (int i = 0; i < bytes.length; i += 3) {
@@ -446,4 +449,24 @@ public class ApplicationPushBuilder impl
return new String(bytes, charset);
}
+
+
+ private static String generateCookieHeader(List<Cookie> cookies, CookieProcessor cookieProcessor) {
+ StringBuilder result = new StringBuilder();
+ boolean first = true;
+ for (Cookie cookie : cookies) {
+ if (first) {
+ first = false;
+ } else {
+ result.append(';');
+ }
+ // The cookie header value generated by the CookieProcessor was
+ // originally intended for the Set-Cookie header on the response.
+ // However, if passed a Cookie with just a name and value set it
+ // will generate an appropriate header for the Cookie header on the
+ // pushed request.
+ result.append(cookieProcessor.generateHeader(cookie));
+ }
+ return result.toString();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org