You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wink.apache.org by "Chris Francuz (JIRA)" <ji...@apache.org> on 2010/10/06 03:22:31 UTC

[jira] Created: (WINK-317) HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header

HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header
------------------------------------------------------------------------------------

                 Key: WINK-317
                 URL: https://issues.apache.org/jira/browse/WINK-317
             Project: Wink
          Issue Type: Bug
          Components: Server
    Affects Versions: 1.1.1
            Reporter: Chris Francuz
            Priority: Minor


org.apache.wink.server.internal.contexts.HttpHeadersImpl.getCookies() iterates over cookie headers but does not iterate over cookies within the header that are split by a semicolon. \\
\\
As a result, only 1 cookie is ever returned. This affects using the javax.ws.rs.core.HttpHeaders interface, as well as the javax.ws.rs.CookieParam annotation.\\
\\
The fix would be to split the cookie header on the semicolon character, as per [RFC 2965|http://www.apps.ietf.org/rfc/rfc2965.html].  A fix implementation would be:
\\
\\
{noformat} 

    public Map<String, Cookie> getCookies() {
        if (cookies == null) {
            cookies = new HashMap<String, Cookie>();
            List<String> cookiesHeaders = headers.get(HttpHeaders.COOKIE);
            if (cookiesHeaders != null) {
                for (String cookieHeader : cookiesHeaders) {
                if (cookieHeader != null){
                    for (String cookieText : split(cookieHeader, ';')){
                        Cookie cookie = Cookie.valueOf(cookieText);
                        if (cookie != null){
                            cookies.put(cookie.getName(), cookie);
                        }
                    }
                }
                }
            }
        }
        return cookies;
    }
{noformat}  
(using org.apache.commons.lang.StringUtils.split() )

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WINK-317) HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-317?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12918614#action_12918614 ] 

Hudson commented on WINK-317:
-----------------------------

Integrated in Wink-Trunk-JDK1.5 #391 (See [https://hudson.apache.org/hudson/job/Wink-Trunk-JDK1.5/391/])
    Fix issue with multiple cookies in single header

See [WINK-317]

Thanks to Chris Francuz for reporting the issue.


> HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header
> ------------------------------------------------------------------------------------
>
>                 Key: WINK-317
>                 URL: https://issues.apache.org/jira/browse/WINK-317
>             Project: Wink
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 1.1.1
>            Reporter: Chris Francuz
>            Assignee: Bryant Luk
>            Priority: Minor
>             Fix For: 1.1.2
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> org.apache.wink.server.internal.contexts.HttpHeadersImpl.getCookies() iterates over cookie headers but does not iterate over cookies within the header that are split by a semicolon. \\
> \\
> As a result, only 1 cookie is ever returned. This affects using the javax.ws.rs.core.HttpHeaders interface, as well as the javax.ws.rs.CookieParam annotation.\\
> \\
> The fix would be to split the cookie header on the semicolon character, as per [RFC 2965|http://www.apps.ietf.org/rfc/rfc2965.html].  A fix implementation would be:
> \\
> \\
> {noformat} 
>     public Map<String, Cookie> getCookies() {
>         if (cookies == null) {
>             cookies = new HashMap<String, Cookie>();
>             List<String> cookiesHeaders = headers.get(HttpHeaders.COOKIE);
>             if (cookiesHeaders != null) {
>                 for (String cookieHeader : cookiesHeaders) {
>                 if (cookieHeader != null){
>                     for (String cookieText : split(cookieHeader, ';')){
>                         Cookie cookie = Cookie.valueOf(cookieText);
>                         if (cookie != null){
>                             cookies.put(cookie.getName(), cookie);
>                         }
>                     }
>                 }
>                 }
>             }
>         }
>         return cookies;
>     }
> {noformat}  
> (using org.apache.commons.lang.StringUtils.split() )

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WINK-317) HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-317?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryant Luk resolved WINK-317.
-----------------------------

       Resolution: Fixed
    Fix Version/s: 1.1.2
         Assignee: Bryant Luk

I think I fixed the issue.  Copied some code from the CookieHeaderDelegate which is what we called originally but made it parse multiple cookies.

> HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header
> ------------------------------------------------------------------------------------
>
>                 Key: WINK-317
>                 URL: https://issues.apache.org/jira/browse/WINK-317
>             Project: Wink
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 1.1.1
>            Reporter: Chris Francuz
>            Assignee: Bryant Luk
>            Priority: Minor
>             Fix For: 1.1.2
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> org.apache.wink.server.internal.contexts.HttpHeadersImpl.getCookies() iterates over cookie headers but does not iterate over cookies within the header that are split by a semicolon. \\
> \\
> As a result, only 1 cookie is ever returned. This affects using the javax.ws.rs.core.HttpHeaders interface, as well as the javax.ws.rs.CookieParam annotation.\\
> \\
> The fix would be to split the cookie header on the semicolon character, as per [RFC 2965|http://www.apps.ietf.org/rfc/rfc2965.html].  A fix implementation would be:
> \\
> \\
> {noformat} 
>     public Map<String, Cookie> getCookies() {
>         if (cookies == null) {
>             cookies = new HashMap<String, Cookie>();
>             List<String> cookiesHeaders = headers.get(HttpHeaders.COOKIE);
>             if (cookiesHeaders != null) {
>                 for (String cookieHeader : cookiesHeaders) {
>                 if (cookieHeader != null){
>                     for (String cookieText : split(cookieHeader, ';')){
>                         Cookie cookie = Cookie.valueOf(cookieText);
>                         if (cookie != null){
>                             cookies.put(cookie.getName(), cookie);
>                         }
>                     }
>                 }
>                 }
>             }
>         }
>         return cookies;
>     }
> {noformat}  
> (using org.apache.commons.lang.StringUtils.split() )

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WINK-317) HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-317?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12918577#action_12918577 ] 

Bryant Luk commented on WINK-317:
---------------------------------

Please let me know if this resolves the issue for you or if you see any issues (there's a Subversion commits tab in JIRA for the exact file changes).  I added some simple tests but if you have one in particular please feel free to attach a patch.

> HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header
> ------------------------------------------------------------------------------------
>
>                 Key: WINK-317
>                 URL: https://issues.apache.org/jira/browse/WINK-317
>             Project: Wink
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 1.1.1
>            Reporter: Chris Francuz
>            Assignee: Bryant Luk
>            Priority: Minor
>             Fix For: 1.1.2
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> org.apache.wink.server.internal.contexts.HttpHeadersImpl.getCookies() iterates over cookie headers but does not iterate over cookies within the header that are split by a semicolon. \\
> \\
> As a result, only 1 cookie is ever returned. This affects using the javax.ws.rs.core.HttpHeaders interface, as well as the javax.ws.rs.CookieParam annotation.\\
> \\
> The fix would be to split the cookie header on the semicolon character, as per [RFC 2965|http://www.apps.ietf.org/rfc/rfc2965.html].  A fix implementation would be:
> \\
> \\
> {noformat} 
>     public Map<String, Cookie> getCookies() {
>         if (cookies == null) {
>             cookies = new HashMap<String, Cookie>();
>             List<String> cookiesHeaders = headers.get(HttpHeaders.COOKIE);
>             if (cookiesHeaders != null) {
>                 for (String cookieHeader : cookiesHeaders) {
>                 if (cookieHeader != null){
>                     for (String cookieText : split(cookieHeader, ';')){
>                         Cookie cookie = Cookie.valueOf(cookieText);
>                         if (cookie != null){
>                             cookies.put(cookie.getName(), cookie);
>                         }
>                     }
>                 }
>                 }
>             }
>         }
>         return cookies;
>     }
> {noformat}  
> (using org.apache.commons.lang.StringUtils.split() )

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WINK-317) HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-317?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12918553#action_12918553 ] 

Bryant Luk commented on WINK-317:
---------------------------------

Hi, still taking a look at this issue.  Probably early in the morning but I don't think we can just do the split on ";" since the cookie attribute for Path, Domain, etc. separate the values by ";".

> HttpHeadersImpl.getCookies() only ever returns the first cookie in the Cookie header
> ------------------------------------------------------------------------------------
>
>                 Key: WINK-317
>                 URL: https://issues.apache.org/jira/browse/WINK-317
>             Project: Wink
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 1.1.1
>            Reporter: Chris Francuz
>            Priority: Minor
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> org.apache.wink.server.internal.contexts.HttpHeadersImpl.getCookies() iterates over cookie headers but does not iterate over cookies within the header that are split by a semicolon. \\
> \\
> As a result, only 1 cookie is ever returned. This affects using the javax.ws.rs.core.HttpHeaders interface, as well as the javax.ws.rs.CookieParam annotation.\\
> \\
> The fix would be to split the cookie header on the semicolon character, as per [RFC 2965|http://www.apps.ietf.org/rfc/rfc2965.html].  A fix implementation would be:
> \\
> \\
> {noformat} 
>     public Map<String, Cookie> getCookies() {
>         if (cookies == null) {
>             cookies = new HashMap<String, Cookie>();
>             List<String> cookiesHeaders = headers.get(HttpHeaders.COOKIE);
>             if (cookiesHeaders != null) {
>                 for (String cookieHeader : cookiesHeaders) {
>                 if (cookieHeader != null){
>                     for (String cookieText : split(cookieHeader, ';')){
>                         Cookie cookie = Cookie.valueOf(cookieText);
>                         if (cookie != null){
>                             cookies.put(cookie.getName(), cookie);
>                         }
>                     }
>                 }
>                 }
>             }
>         }
>         return cookies;
>     }
> {noformat}  
> (using org.apache.commons.lang.StringUtils.split() )

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.