You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Padraig O'hIceadha <Pa...@sabre.com> on 2003/03/07 15:59:48 UTC

[PATCH] HttpClient was rejecting some cookies a browser would accept

Hi,

    I found that cookies generated by WebLogic were being rejected by 
HttpClient as it didn't like the format of the Expires field.

    From reading the specs I think that HttpClient is not at fault, in 
that WebLogic does not seem to be using a 100% correct date format.

    However their error is minor (it uses incorrect case for the
day and month names) and I think it would be useful if HttpClient
were forgiving in this regard.

    For example, WebLogic sends
expires=thursday, 06-mar-2003 04:44:00 GMT
    where it should send
expires=Thursday, 06-Mar-2003 04:44:00 GMT

     This causes a problem in the parse method in HeaderElement
where it has extra code for recognising when a , in the cookie
string is part of a date.

     To check this it does a case sensitive match against all the
valid combinations ("Monday", "Tuesday" etc). As the match is
case sensitive it doesn't recognise the weblogic expires as a
date and the expires field ends up simply as "thursday", which
later fails parsing by SimpleDateFormat.

     The patch below changes this to use a case insensitive
comparison.

     Regards,

       Padraig

Index: HeaderElement.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java,v
retrieving revision 1.16
diff -u -r1.16 HeaderElement.java
--- HeaderElement.java  31 Jan 2003 00:33:36 -0000      1.16
+++ HeaderElement.java  7 Mar 2003 14:41:07 -0000
@@ -300,22 +300,24 @@
                   * the expires date format is "Wdy, DD-Mon-YY HH:MM:SS 
GMT".
                   * Notice that there is always comma(',') sign.
                   * For the general cases, rfc1123-date, rfc850-date.
+                * NB some servers send the day & month names in the 
wrong case
                   */
                  if (tokenizer.hasMoreTokens()) {
-                    if (nextToken.endsWith("Mon")
-                        || nextToken.endsWith("Tue")
-                        || nextToken.endsWith("Wed")
-                        || nextToken.endsWith("Thu")
-                        || nextToken.endsWith("Fri")
-                        || nextToken.endsWith("Sat")
-                        || nextToken.endsWith("Sun")
-                        || nextToken.endsWith("Monday")
-                        || nextToken.endsWith("Tuesday")
-                        || nextToken.endsWith("Wednesday")
-                        || nextToken.endsWith("Thursday")
-                        || nextToken.endsWith("Friday")
-                        || nextToken.endsWith("Saturday")
-                        || nextToken.endsWith("Sunday")) {
+                   String possibleExpiresField = nextToken.toLowerCase();
+                    if (possibleExpiresField.endsWith("mon")
+                        || possibleExpiresField.endsWith("tue")
+                        || possibleExpiresField.endsWith("wed")
+                        || possibleExpiresField.endsWith("thu")
+                        || possibleExpiresField.endsWith("fri")
+                        || possibleExpiresField.endsWith("sat")
+                        || possibleExpiresField.endsWith("sun")
+                        || possibleExpiresField.endsWith("monday")
+                        || possibleExpiresField.endsWith("tuesday")
+                        || possibleExpiresField.endsWith("wednesday")
+                        || possibleExpiresField.endsWith("thursday")
+                        || possibleExpiresField.endsWith("friday")
+                        || possibleExpiresField.endsWith("saturday")
+                        || possibleExpiresField.endsWith("sunday")) {

                          nextToken += "," + tokenizer.nextToken();
                      }