Example usage for org.apache.http.client.methods HttpRequestWrapper getHeaders

List of usage examples for org.apache.http.client.methods HttpRequestWrapper getHeaders

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpRequestWrapper getHeaders.

Prototype

public Header[] getHeaders(String str) 

Source Link

Usage

From source file:org.apache.http.impl.client.cache.CachingExec.java

private boolean mayCallBackend(final HttpRequestWrapper request) {
    for (final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
        for (final HeaderElement elt : h.getElements()) {
            if ("only-if-cached".equals(elt.getName())) {
                log.trace("Request marked only-if-cached");
                return false;
            }/*from w w w.  j a v  a 2  s .  c  om*/
        }
    }
    return true;
}

From source file:org.apache.http.impl.client.cache.CachingExec.java

private boolean explicitFreshnessRequest(final HttpRequestWrapper request, final HttpCacheEntry entry,
        final Date now) {
    for (final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
        for (final HeaderElement elt : h.getElements()) {
            if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) {
                try {
                    final int maxstale = Integer.parseInt(elt.getValue());
                    final long age = validityPolicy.getCurrentAgeSecs(entry, now);
                    final long lifetime = validityPolicy.getFreshnessLifetimeSecs(entry);
                    if (age - lifetime > maxstale) {
                        return true;
                    }/*from  w ww .j  ava2  s.  com*/
                } catch (final NumberFormatException nfe) {
                    return true;
                }
            } else if (HeaderConstants.CACHE_CONTROL_MIN_FRESH.equals(elt.getName())
                    || HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName())) {
                return true;
            }
        }
    }
    return false;
}