hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Brown" <bro...@reflexe.fr>
Subject Re: Parsing "Last-Modified" HTTP response header
Date Fri, 11 Apr 2003 16:36:13 GMT

Oleg,

I hope it proves to be a useful addition... you're welcome to use it, but
I'm not up to speed on your development methodology, and wouldn't want to
screw things up for you.  I'm afraid I don't have much free time to
contribute (I'd love to: I've a ton of projects in mind...).  So this time,
maybe someone else should integrate it.

Hope it helps anyway,
Chris

----- Original Message -----
From: "Kalnichevski, Oleg" <oleg.kalnichevski@bearingpoint.com>
To: "Commons HttpClient Project" <commons-httpclient-dev@jakarta.apache.org>
Sent: Friday, April 11, 2003 5:11 PM
Subject: RE: Parsing "Last-Modified" HTTP response header


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




Mime
View raw message