hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kalnichevski, Oleg" <oleg.kalnichev...@bearingpoint.com>
Subject RE: Parsing "Last-Modified" HTTP response header
Date Fri, 11 Apr 2003 15:11:23 GMT
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


Mime
View raw message