Esempio n. 1
0
 /** Sets the {@code "Date"} header. */
 public static void setDate(HttpMessage message, Date value) {
   if (value != null) {
     message.headers().set(Names.DATE, HttpHeaderDateFormat.get().format(value));
   } else {
     message.headers().set(Names.DATE, null);
   }
 }
Esempio n. 2
0
 /**
  * Sets a new date header with the specified name and value. If there is an existing header with
  * the same name, the existing header is removed. The specified value is formatted as defined in
  * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>
  */
 public static void setDateHeader(HttpMessage message, CharSequence name, Date value) {
   if (value != null) {
     message.headers().set(name, HttpHeaderDateFormat.get().format(value));
   } else {
     message.headers().set(name, null);
   }
 }
Esempio n. 3
0
 /**
  * Returns the date header value with the specified header name. If there are more than one header
  * value for the specified header name, the first value is returned.
  *
  * @return the header value
  * @throws ParseException if there is no such header or the header value is not a formatted date
  */
 public static Date getDateHeader(HttpMessage message, CharSequence name) throws ParseException {
   String value = getHeader(message, name);
   if (value == null) {
     throw new ParseException("header not found: " + name, 0);
   }
   return HttpHeaderDateFormat.get().parse(value);
 }
Esempio n. 4
0
  /**
   * Returns the date header value with the specified header name. If there are more than one header
   * value for the specified header name, the first value is returned.
   *
   * @return the header value or the {@code defaultValue} if there is no such header or the header
   *     value is not a formatted date
   */
  public static Date getDateHeader(HttpMessage message, CharSequence name, Date defaultValue) {
    final String value = getHeader(message, name);
    if (value == null) {
      return defaultValue;
    }

    try {
      return HttpHeaderDateFormat.get().parse(value);
    } catch (ParseException e) {
      return defaultValue;
    }
  }