commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsde...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie HttpMethodBase.java
Date Sun, 08 Dec 2002 18:51:07 GMT
jsdever     2002/12/08 10:51:07

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
  Removed:     httpclient/src/java/org/apache/commons/httpclient/cookie
                        HttpMethodBase.java
  Log:
  Fix a patch problem with HttpMethodBase.
  
  Revision  Changes    Path
  1.84      +56 -21    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.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- HttpMethodBase.java	3 Dec 2002 15:28:18 -0000	1.83
  +++ HttpMethodBase.java	8 Dec 2002 18:51:06 -0000	1.84
  @@ -76,6 +76,8 @@
   import java.util.Set;
   import java.util.StringTokenizer;
   
  +import org.apache.commons.httpclient.cookie.CookiePolicy;
  +import org.apache.commons.httpclient.cookie.CookieSpec;
   import org.apache.commons.httpclient.util.URIUtil;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -1190,14 +1192,28 @@
           log.trace("enter HttpMethodBase.addCookieRequestHeader(HttpState, "
                     + "HttpConnection)");
   
  -        Header cookieHeader = Cookie.createCookieHeader(conn.getHost(),
  -                                                        conn.getPort(),
  -                                                        getPath(),
  -                                                        conn.isSecure(),
  -                                                        new Date(),
  -                                                        state.getCookies());
  -        if (null != cookieHeader) {
  -            setRequestHeader(cookieHeader);
  +        CookieSpec matcher = CookiePolicy.getDefaultSpec();
  +        Cookie[] cookies = matcher.match(
  +          conn.getHost(),
  +          conn.getPort(),
  +          getPath(),
  +          conn.isSecure(),
  +          state.getCookies());
  +        if ((cookies != null) && (cookies.length > 0))
  +        {
  +            if (this.strictMode)
  +            {
  +                // If in strict mode put all cookie in one header
  +                setRequestHeader(matcher.formatCookieHeader(cookies));
  +            }
  +            else
  +            {
  +                // If not in strict mode put each cookie in a separate header
  +                for(int i = 0; i < cookies.length; i++)
  +                {
  +                    setRequestHeader(matcher.formatCookieHeader(cookies[i]));
  +                }
  +            }
           }
       }
   
  @@ -1471,16 +1487,35 @@
               setCookieHeader = getResponseHeader("set-cookie");
           }
   
  -        if (setCookieHeader != null) {
  -            try {
  -                Cookie[] cookies = Cookie.parse(conn.getHost(), conn.getPort(),
  -                                                getPath(), conn.isSecure(),
  -                                                setCookieHeader);
  -                state.addCookies(cookies);
  -            } catch (HttpException e) {
  -                if (log.isWarnEnabled()) {
  -                    log.warn("Cookie rejected: \"" + setCookieHeader.getValue() + "\".
" + e.getMessage());
  +        if (setCookieHeader == null) return;
  +        try {
  +
  +            CookieSpec parser = CookiePolicy.getDefaultSpec();
  +            Cookie[] cookies = parser.parse(
  +              conn.getHost(), 
  +              conn.getPort(),
  +              getPath(), 
  +              conn.isSecure(),
  +              setCookieHeader);
  +            for (int i = 0; i < cookies.length; i++)
  +            {
  +                Cookie cookie = cookies[i];
  +                CookieSpec validator = CookiePolicy.getSpecByVersion(cookie.getVersion());
  +                validator.validate(
  +                  conn.getHost(), 
  +                  conn.getPort(),
  +                  getPath(), 
  +                  conn.isSecure(),
  +                  cookie);
  +                if (log.isDebugEnabled()) {
  +                    log.debug("Cookie accepted: \"" + validator.formatCookie(cookie) +
"\"");
                   }
  +                state.addCookie(cookie);
  +            }
  +              
  +        } catch (HttpException e) {
  +            if (log.isWarnEnabled()) {
  +                log.warn("Cookie rejected: \"" + setCookieHeader.getValue() + "\". " +
e.getMessage());
               }
           }
       }
  
  
  

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


Mime
View raw message