hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: Parsing "Last-Modified" HTTP response header
Date Sat, 12 Apr 2003 22:30:44 GMT
Sounds good.  I will use all of the formats for both cookies and 
headers.

Mike

On Saturday, April 12, 2003, at 06:16 PM, Oleg Kalnichevski wrote:

> Mike,
> In this world people routinely ignore RFCs. I think HttpClient has to
> have a high degree of tolerance to those non-compliant date formats.
> Besides, since we allow non-compliant variations in cookies, we should
> treat other headers consistently.
>
> Oleg
>
> On Sat, 2003-04-12 at 23:28, Michael Becke wrote:
>> I'm going to go ahead and add this.  One question.  There seems to be 
>> a
>> number of other date formats used by the cookie parser.  They mostly
>> look like slight variations on the RFC 1123 and 1035 ones.  Should we
>> also be using these for header date values?
>>
>> Mike
>>
>> On Friday, April 11, 2003, at 11:11 AM, Kalnichevski, Oleg wrote:
>>
>>> Chris,
>>>
>>> I (personally) see this code as a valuable addition to
>>> org.apache.commons.httpclient.contrib or
>>> org.apache.commons.httpclient.utils packages. Do you mind investing a
>>> bit more of your time to massage this code into DateParser class or
>>> something of a sort? It would also be quite nice to factor out cookie
>>> 'expire' attribute parsing logic and merge it into this class.
>>>
>>> Cheers
>>>
>>> Oleg
>>> -----Original Message-----
>>> From: Chris Brown [mailto:brown2@reflexe.fr]
>>> Sent: Friday, April 11, 2003 16:51
>>> To: Commons HttpClient Project
>>> Subject: Re: Parsing "Last-Modified" HTTP response header
>>>
>>>
>>>
>>> Well, I'm an impatient chap... didn't find the code, so I coded it
>>> myself.
>>>
>>> Here as a reference for anyone else (maybe worth including in the 
>>> API,
>>> once
>>> it's been verified).  Careful with line breaks...
>>> ____________________________________________________________
>>>
>>>  /**
>>>   * Date format pattern used to parse HTTP date headers in RFC 1123
>>> format.
>>>   * <p>Dates may be formatted using the following patterns (listed in
>>> order
>>>   * of preference):</p>
>>>   * <ol>
>>>   * <li><code>RFC 1123 format</code> (recommended)</li>
>>>   * <li>{@link #PATTERN_RFC1036 RFC 1036 format) (deprecated)</li>
>>>   * <li>{@link #PATTERN_ASCTIME ANSI C asctime() format}
>>> (deprecated)</li>
>>>   * </ol>
>>>   */
>>>  public static final String PATTERN_RFC1123 =
>>>  "EEE, dd MMM yyyy HH:mm:ss zzz";
>>>
>>>  /**
>>>   * Date format pattern used to parse HTTP date headers in RFC 1036
>>> format.
>>>   * <p>Dates may be formatted using the following patterns (listed in
>>> order
>>>   * of preference):</p>
>>>   * <ol>
>>>   * <li>{@link #PATTERN_RFC1123 RFC 1123 format} (recommended)</li>
>>>   * <li><code>RFC 1036 format</code> (deprecated)</li>
>>>   * <li>{@link #PATTERN_ASCTIME ANSI C asctime() format}
>>> (deprecated)</li>
>>>   * </ol>
>>>   */
>>>  public static final String PATTERN_RFC1036 =
>>>  "EEEE, dd-MMM-yy HH:mm:ss zzz";
>>>
>>>  /**
>>>   * Date format pattern used to parse HTTP date headers in ANSI C
>>> <code>asctime()</code> format.
>>>   * <p>Dates may be formatted using the following patterns (listed in
>>> order
>>>   * of preference):</p>
>>>   * <ol>
>>>   * <li>{@link #PATTERN_RFC1123 RFC 1123 format} (recommended)</li>
>>>   * <li>{@link #PATTERN_RFC1036 RFC 1036 format) (deprecated)</li>
>>>   * <li><code>ANSI C asctime() format</code> (deprecated)</li>
>>>   * </ol>
>>>   */
>>>  public static final String PATTERN_ASCTIME =
>>>  "EEE MMM d HH:mm:ss yyyy";
>>>
>>>  /**
>>>   * Parses a HTTP header date value.
>>>   *
>>>   * @param dateHeaderValue the date header value to parse.
>>>   * @return the parsed date.
>>>   *
>>>   * @throws ParseException if the date could not be parsed according
>>> to the
>>>   *  one of the following formats (in order of preference):
>>>   *  {@link #PATTERN_RFC1123 RFC 1123},
>>>   *  {@link #PATTERN_RFC1036 RFC 1036},
>>>   *  {@link #PATTERN_ASCTIME ANSI C asctime() format}.
>>>   *
>>>   *  @author Christopher Brown
>>>   */
>>>  public static Date parseDateHeader(String dateHeaderValue) throws
>>> ParseException
>>>  {
>>>   Date date = null;
>>>   if (dateHeaderValue != null)
>>>   {
>>>    SimpleDateFormat dateParser = new 
>>> SimpleDateFormat(PATTERN_RFC1123,
>>> Locale.US);
>>>    dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
>>>    try
>>>    {
>>>     date = dateParser.parse(dateHeaderValue);
>>>    }
>>>    catch (ParseException exRFC1123)
>>>    {
>>>     dateParser.applyPattern(PATTERN_RFC1036);
>>>     try
>>>     {
>>>      date = dateParser.parse(dateHeaderValue);
>>>     }
>>>     catch (ParseException exRFC1036)
>>>     {
>>>      dateParser.applyPattern(PATTERN_ASCTIME);
>>>      date = dateParser.parse(dateHeaderValue);
>>>     }
>>>    }
>>>   }
>>>   return date;
>>>  }
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> commons-httpclient-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:
>>> commons-httpclient-dev-help@jakarta.apache.org
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> commons-httpclient-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:
>>> commons-httpclient-dev-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: 
>> commons-httpclient-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: 
>> commons-httpclient-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


Mime
View raw message