commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpMethodBase.java
Date Sun, 16 Feb 2003 17:56:17 GMT
olegk       2003/02/16 09:56:17

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
  Log:
  Changelog:
  
  - fix for inconsistent cookie rejection in HttpMethodBase#ParseResponseHeaders method
  
  Reported by by James Couball <James.Couball@cotelligent.com>
  Contributed by James Couball
  Reviewed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.113     +46 -36    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -r1.112 -r1.113
  --- HttpMethodBase.java	16 Feb 2003 13:08:32 -0000	1.112
  +++ HttpMethodBase.java	16 Feb 2003 17:56:17 -0000	1.113
  @@ -73,6 +73,7 @@
   import java.util.Set;
   import java.util.StringTokenizer;
   
  +import org.apache.commons.httpclient.cookie.MalformedCookieException;
   import org.apache.commons.httpclient.cookie.CookiePolicy;
   import org.apache.commons.httpclient.cookie.CookieSpec;
   import org.apache.commons.httpclient.util.URIUtil;
  @@ -1586,45 +1587,54 @@
           LOG.trace("enter HttpMethodBase.processResponseHeaders(HttpState, "
               + "HttpConnection)");
   
  -        // add cookies, if any
  -        // should we set cookies?
  -        Header setCookieHeader = getResponseHeader("set-cookie2");
  -        if (null == setCookieHeader) { //ignore old-style if new is supported
  -            setCookieHeader = getResponseHeader("set-cookie");
  +        Header[] headers = getResponseHeaderGroup().getHeaders("set-cookie2");
  +        //Only process old style set-cookie headers if new style headres
  +        //are not present
  +        if (headers.length == 0) { 
  +            headers = getResponseHeaderGroup().getHeaders("set-cookie");
           }
  -
  -        if (setCookieHeader == null) { 
  -            return;
  -        }
  -        try {
  -
  -            CookieSpec parser = CookiePolicy.getSpecByPolicy(state.getCookiePolicy());
  -            Cookie[] cookies = parser.parse(
  -              conn.getHost(),
  -              conn.getPort(),
  -              getPath(),
  -              conn.isSecure(),
  -              setCookieHeader);
  -            for (int i = 0; i < cookies.length; i++) {
  -                Cookie cookie = cookies[i];
  -                parser.validate(
  +        
  +        CookieSpec parser = CookiePolicy.getSpecByPolicy(state.getCookiePolicy());
  +        for (int i = 0; i < headers.length; i++) {
  +            Header header = headers[i];
  +            Cookie[] cookies = null;
  +            try {
  +                cookies = parser.parse(
                     conn.getHost(),
                     conn.getPort(),
                     getPath(),
                     conn.isSecure(),
  -                  cookie);
  -                if (LOG.isDebugEnabled()) {
  -                    LOG.debug("Cookie accepted: \"" 
  -                        + parser.formatCookie(cookie) + "\"");
  +                  header);
  +            } catch (MalformedCookieException e) {
  +                if (LOG.isWarnEnabled()) {
  +                    LOG.warn("Invalid cookie header: \"" 
  +                        + header.getValue() 
  +                        + "\". " + e.getMessage());
                   }
  -                state.addCookie(cookie);
               }
  -
  -        } catch (HttpException e) {
  -            if (LOG.isWarnEnabled()) {
  -                LOG.warn("Cookie rejected: \"" 
  -                    + setCookieHeader.getValue() 
  -                    + "\". " + e.getMessage());
  +            if (cookies != null) {
  +                for (int j = 0; j < cookies.length; j++) {
  +                    Cookie cookie = cookies[j];
  +                    try {
  +                        parser.validate(
  +                          conn.getHost(),
  +                          conn.getPort(),
  +                          getPath(),
  +                          conn.isSecure(),
  +                          cookie);
  +                        state.addCookie(cookie);
  +                        if (LOG.isDebugEnabled()) {
  +                            LOG.debug("Cookie accepted: \"" 
  +                                + parser.formatCookie(cookie) + "\"");
  +                        }
  +                    } catch(MalformedCookieException e) {
  +                        if (LOG.isWarnEnabled()) {
  +                            LOG.warn("Cookie rejected: \"" 
  +                                + parser.formatCookie(cookie) + 
  +                                "\". " + e.getMessage());
  +                        }
  +                    }
  +                }
               }
           }
       }
  
  
  

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


Mime
View raw message