cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6693] Support for a $ char in HttpHeaderImpl.getCookies
Date Mon, 30 Nov 2015 14:19:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes d59b780fc -> c3afe9d03


[CXF-6693] Support for a $ char in HttpHeaderImpl.getCookies


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c3afe9d0
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c3afe9d0
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c3afe9d0

Branch: refs/heads/3.0.x-fixes
Commit: c3afe9d034bff69d35617faae55a0a2453e65f8d
Parents: d59b780
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Nov 30 14:10:43 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Nov 30 14:19:02 2015 +0000

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/impl/HttpHeadersImpl.java  | 34 ++++++++++++++++----
 .../cxf/jaxrs/impl/HttpHeadersImplTest.java     | 23 +++++++++++--
 2 files changed, 48 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c3afe9d0/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
index d692964..a082fac 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
@@ -57,6 +57,10 @@ public class HttpHeadersImpl implements HttpHeaders {
     private static final String COOKIE_SEPARATOR_CRLF = "crlf";
     private static final String DEFAULT_SEPARATOR = ",";
     private static final String DEFAULT_COOKIE_SEPARATOR = ";";
+    private static final String DOLLAR_CHAR = "$";
+    private static final String COOKIE_VERSION_PARAM = DOLLAR_CHAR + "Version";
+    private static final String COOKIE_PATH_PARAM = DOLLAR_CHAR + "Path";
+    private static final String COOKIE_DOMAIN_PARAM = DOLLAR_CHAR + "Domain";
     
     private static final String COMPLEX_HEADER_EXPRESSION = 
         "(([\\w]+=\"[^\"]*\")|([\\w]+=[\\w]+)|([\\w]+))(;(([\\w]+=\"[^\"]*\")|([\\w]+=[\\w]+)|([\\w]+)))?";
@@ -110,9 +114,10 @@ public class HttpHeadersImpl implements HttpHeaders {
             if (value == null) {
                 continue;
             }
-            List<String> cs = value.contains("$")
-                ? Collections.singletonList(value)
-                : getHeaderValues(HttpHeaders.COOKIE, value, getCookieSeparator());
+            
+            
+            List<String> cs = getHeaderValues(HttpHeaders.COOKIE, value, 
+                                              getCookieSeparator(value));
             for (String c : cs) {
                 Cookie cookie = Cookie.valueOf(c);
                 cl.put(cookie.getName(), cookie);
@@ -121,7 +126,22 @@ public class HttpHeadersImpl implements HttpHeaders {
         return cl;
     }
 
-    private String getCookieSeparator() {
+    private String getCookieSeparator(String value) {
+        String separator = getCookieSeparatorFromProperty();
+        if (separator != null) {
+            return separator;
+        } else {
+            if (value.contains(DOLLAR_CHAR)
+                && (value.contains(COOKIE_VERSION_PARAM)
+                    || value.contains(COOKIE_PATH_PARAM)
+                    || value.contains(COOKIE_DOMAIN_PARAM))) {
+                return DEFAULT_SEPARATOR;
+            }
+            
+            return DEFAULT_COOKIE_SEPARATOR;
+        }
+    }
+    private String getCookieSeparatorFromProperty() {
         Object cookiePropValue = message.getContextualProperty(COOKIE_SEPARATOR_PROPERTY);
         if (cookiePropValue != null) {
             String separator = cookiePropValue.toString().trim();
@@ -133,9 +153,9 @@ public class HttpHeadersImpl implements HttpHeaders {
             }
             return separator;
         } else {
-            return DEFAULT_COOKIE_SEPARATOR;
+            return null;
         }
-    }
+    }    
     
     public Locale getLanguage() {
         List<String> values = getListValues(HttpHeaders.CONTENT_LANGUAGE);
@@ -212,7 +232,7 @@ public class HttpHeadersImpl implements HttpHeaders {
             if (value == null) {
                 continue;
             }
-            String sep = HttpHeaders.COOKIE.equalsIgnoreCase(name) ? getCookieSeparator()
: DEFAULT_SEPARATOR;
+            String sep = HttpHeaders.COOKIE.equalsIgnoreCase(name) ? getCookieSeparator(value)
: DEFAULT_SEPARATOR;
             ls.addAll(getHeaderValues(name, value, sep));
         }
         return ls;

http://git-wip-us.apache.org/repos/asf/cxf/blob/c3afe9d0/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
index c82af5d..314b87e 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
@@ -396,12 +396,12 @@ public class HttpHeadersImplTest extends Assert {
         Message m = new MessageImpl();
         m.setExchange(new ExchangeImpl());
         MetadataMap<String, String> headers = createHeaders();
-        headers.putSingle(HttpHeaders.COOKIE, "a=b;c=d");
+        headers.putSingle(HttpHeaders.COOKIE, "a=$b;c=d");
         m.put(Message.PROTOCOL_HEADERS, headers);
         HttpHeaders h = new HttpHeadersImpl(m);
         Map<String, Cookie> cookies = h.getCookies();
         assertEquals(2, cookies.size());
-        assertEquals("b", cookies.get("a").getValue());
+        assertEquals("$b", cookies.get("a").getValue());
         assertEquals("d", cookies.get("c").getValue());
     }
     
@@ -421,6 +421,25 @@ public class HttpHeadersImplTest extends Assert {
         assertEquals(1, cookie.getVersion());
     }
     
+    @Test
+    public void testGetCookiesWithAttributes() throws Exception {
+        
+        Message m = new MessageImpl();
+        m.setExchange(new ExchangeImpl());
+        MetadataMap<String, String> headers = createHeaders();
+        headers.putSingle(HttpHeaders.COOKIE, "$Version=1;a=b, $Version=1;c=d");
+        m.put(Message.PROTOCOL_HEADERS, headers);
+        HttpHeaders h = new HttpHeadersImpl(m);
+        Map<String, Cookie> cookies = h.getCookies();
+        assertEquals(2, cookies.size());
+        Cookie cookieA = cookies.get("a");
+        assertEquals("b", cookieA.getValue());
+        assertEquals(1, cookieA.getVersion());
+        Cookie cookieC = cookies.get("c");
+        assertEquals("d", cookieC.getValue());
+        assertEquals(1, cookieA.getVersion());
+    }
+    
     
     @Test
     public void testGetCookiesWithComma() throws Exception {


Mime
View raw message