Package com.anthavio.httl.HttpSender

Examples of com.anthavio.httl.HttpSender.Multival


public class HttpHeaderUtil {

  public static CacheEntry<CachedResponse> buildCacheEntry(SenderRequest request, SenderResponse response) {

    Multival headers = response.getHeaders();

    long softTtl = 0; //seconds
    long maxAge = 0; //seconds
    boolean hasCacheControl = false;

    String headerValue = headers.getFirst("Cache-Control");
    if (headerValue != null) {
      hasCacheControl = true;
      String[] tokens = headerValue.split(",");
      for (int i = 0; i < tokens.length; i++) {
        String token = tokens[i].trim();
        if (token.equals("no-store") || token.equals("no-cache")) {
          //always check server for new version (with If-None-Match (ETag) or If-Modified-Since(Last-Modified/Date))
          //if ETag or Last-Modified is not present, we will not cache this reponse at all
          maxAge = 0;
          break;
        } else if (token.equals("must-revalidate") || token.equals("proxy-revalidate")) {
          //cache response until expire (max-age, Expires)
          //then check server for new version (with If-None-Match (ETag) or If-Modified-Since(Last-Modified/Date))
          //when max-age=0 or Expires=-1 then this is same as no-store/no-cache
          maxAge = 0;
        } else if (token.startsWith("max-age=")) {
          try {
            maxAge = Long.parseLong(token.substring(8));//seconds
            break;
          } catch (Exception e) {
            //ignore
          }
        }
      }
    }

    long serverDate = 0;
    headerValue = headers.getFirst("Date");
    if (headerValue != null) {
      serverDate = parseDateAsEpoch(headerValue);
    }

    long serverExpires = 0;
    headerValue = headers.getFirst("Expires");
    if (headerValue != null) {
      serverExpires = parseDateAsEpoch(headerValue);
    }

    long lastModified = 0;
    headerValue = headers.getFirst("Last-Modified");
    if (headerValue != null) {
      lastModified = parseDateAsEpoch(headerValue);
    }
    Date modified = lastModified > 0 ? new Date(lastModified) : null;

    String etag = headers.getFirst("ETag");

    // Cache-Control takes precedence over an Expires header,
    // even if both exist and Expires is more restrictive.
    if (hasCacheControl) {
      softTtl = maxAge;
View Full Code Here


    /**
     * Sets parameters (replacing any existing)
     */
    public X parameters(Map<String, ?> parameters) {
      this.parameters = new Multival(parameters);
      return getX();
    }
View Full Code Here

    }

    if (parameters != null) {
      this.parameters = parameters;
    } else {
      this.parameters = new Multival();
    }

    if (headers != null) {
      this.headers = headers;
    } else {
      this.headers = new Multival();
    }
  }
View Full Code Here

  /**
   * Set Headers replacing all existing
   */
  public SenderRequest setHeaders(Map<String, ?> headers) {
    this.headers = new Multival(headers);
    return this;
  }
View Full Code Here

  /**
   * Set Parameters replacing all existing
   */
  public SenderRequest setParameters(Map<String, ?> parameters) {
    this.parameters = new Multival(parameters);
    return this;
  }
View Full Code Here

TOP

Related Classes of com.anthavio.httl.HttpSender.Multival

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.