当前位置: 首页>>代码示例>>Java>>正文


Java HeaderConstants类代码示例

本文整理汇总了Java中org.apache.http.client.cache.HeaderConstants的典型用法代码示例。如果您正苦于以下问题:Java HeaderConstants类的具体用法?Java HeaderConstants怎么用?Java HeaderConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HeaderConstants类属于org.apache.http.client.cache包,在下文中一共展示了HeaderConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: explicitFreshnessRequest

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
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;
                    }
                } 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;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:CachingHttpClient.java

示例2: clientRequestsOurOptions

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
boolean clientRequestsOurOptions(final HttpRequest request) {
    final RequestLine line = request.getRequestLine();

    if (!HeaderConstants.OPTIONS_METHOD.equals(line.getMethod())) {
        return false;
    }

    if (!"*".equals(line.getUri())) {
        return false;
    }

    if (!"0".equals(request.getFirstHeader(HeaderConstants.MAX_FORWARDS).getValue())) {
        return false;
    }

    return true;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:CachingHttpClient.java

示例3: explicitFreshnessRequest

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
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;
                    }
                } 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;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:CachingExec.java

示例4: mayReturnStaleWhileRevalidating

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
public boolean mayReturnStaleWhileRevalidating(final HttpCacheEntry entry, final Date now) {
    for (final Header h : entry.getHeaders(HeaderConstants.CACHE_CONTROL)) {
        for(final HeaderElement elt : h.getElements()) {
            if (HeaderConstants.STALE_WHILE_REVALIDATE.equalsIgnoreCase(elt.getName())) {
                try {
                    final int allowedStalenessLifetime = Integer.parseInt(elt.getValue());
                    if (getStalenessSecs(entry, now) <= allowedStalenessLifetime) {
                        return true;
                    }
                } catch (final NumberFormatException nfe) {
                    // skip malformed directive
                }
            }
        }
    }

    return false;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:CacheValidityPolicy.java

示例5: mayReturnStaleIfError

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
private boolean mayReturnStaleIfError(final Header[] headers, final long stalenessSecs) {
    boolean result = false;
    for(final Header h : headers) {
        for(final HeaderElement elt : h.getElements()) {
            if (HeaderConstants.STALE_IF_ERROR.equals(elt.getName())) {
                try {
                    final int staleIfErrorSecs = Integer.parseInt(elt.getValue());
                    if (stalenessSecs <= staleIfErrorSecs) {
                        result = true;
                        break;
                    }
                } catch (final NumberFormatException nfe) {
                    // skip malformed directive
                }
            }
        }
    }
    return result;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:CacheValidityPolicy.java

示例6: getAgeValue

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
protected long getAgeValue(final HttpCacheEntry entry) {
    long ageValue = 0;
    for (final Header hdr : entry.getHeaders(HeaderConstants.AGE)) {
        long hdrAge;
        try {
            hdrAge = Long.parseLong(hdr.getValue());
            if (hdrAge < 0) {
                hdrAge = MAX_AGE;
            }
        } catch (final NumberFormatException nfe) {
            hdrAge = MAX_AGE;
        }
        ageValue = (hdrAge > ageValue) ? hdrAge : ageValue;
    }
    return ageValue;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:CacheValidityPolicy.java

示例7: getMaxAge

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
protected long getMaxAge(final HttpCacheEntry entry) {
    long maxage = -1;
    for (final Header hdr : entry.getHeaders(HeaderConstants.CACHE_CONTROL)) {
        for (final HeaderElement elt : hdr.getElements()) {
            if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName())
                    || "s-maxage".equals(elt.getName())) {
                try {
                    final long currMaxAge = Long.parseLong(elt.getValue());
                    if (maxage == -1 || currMaxAge < maxage) {
                        maxage = currMaxAge;
                    }
                } catch (final NumberFormatException nfe) {
                    // be conservative if can't parse
                    maxage = 0;
                }
            }
        }
    }
    return maxage;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:CacheValidityPolicy.java

示例8: stripOtherFreshnessDirectivesWithNoCache

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
private void stripOtherFreshnessDirectivesWithNoCache(final HttpRequest request) {
    final List<HeaderElement> outElts = new ArrayList<HeaderElement>();
    boolean shouldStrip = false;
    for(final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
        for(final HeaderElement elt : h.getElements()) {
            if (!disallowedWithNoCache.contains(elt.getName())) {
                outElts.add(elt);
            }
            if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elt.getName())) {
                shouldStrip = true;
            }
        }
    }
    if (!shouldStrip) {
        return;
    }
    request.removeHeaders(HeaderConstants.CACHE_CONTROL);
    request.setHeader(HeaderConstants.CACHE_CONTROL, buildHeaderFromElements(outElts));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:RequestProtocolCompliance.java

示例9: requestHasWeakETagAndRange

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
private RequestProtocolError requestHasWeakETagAndRange(final HttpRequest request) {
    // TODO: Should these be looking at all the headers marked as Range?
    final String method = request.getRequestLine().getMethod();
    if (!(HeaderConstants.GET_METHOD.equals(method))) {
        return null;
    }

    final Header range = request.getFirstHeader(HeaderConstants.RANGE);
    if (range == null) {
        return null;
    }

    final Header ifRange = request.getFirstHeader(HeaderConstants.IF_RANGE);
    if (ifRange == null) {
        return null;
    }

    final String val = ifRange.getValue();
    if (val.startsWith("W/")) {
        return RequestProtocolError.WEAK_ETAG_AND_RANGE_ERROR;
    }

    return null;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:25,代码来源:RequestProtocolCompliance.java

示例10: expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
private boolean expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl(
        final HttpResponse response) {
    if (response.getFirstHeader(HeaderConstants.CACHE_CONTROL) != null) {
        return false;
    }
    final Header expiresHdr = response.getFirstHeader(HeaderConstants.EXPIRES);
    final Header dateHdr = response.getFirstHeader(HTTP.DATE_HEADER);
    if (expiresHdr == null || dateHdr == null) {
        return false;
    }
    final Date expires = DateUtils.parseDate(expiresHdr.getValue());
    final Date date = DateUtils.parseDate(dateHdr.getValue());
    if (expires == null || date == null) {
        return false;
    }
    return expires.equals(date) || expires.before(date);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:ResponseCachingPolicy.java

示例11: generateResponse

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
/**
 * If I was able to use a {@link CacheEntity} to response to the {@link org.apache.http.HttpRequest} then
 * generate an {@link HttpResponse} based on the cache entry.
 * @param request {@link HttpRequestWrapper} to generate the response for
 * @param entry {@link CacheEntity} to transform into an {@link HttpResponse}
 * @return {@link HttpResponse} that was constructed
 */
CloseableHttpResponse generateResponse(final HttpRequestWrapper request, final HttpCacheEntry entry) {
    final Date now = new Date();
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, entry
            .getStatusCode(), entry.getReasonPhrase());

    response.setHeaders(entry.getAllHeaders());

    if (responseShouldContainEntity(request, entry)) {
        final HttpEntity entity = new CacheEntity(entry);
        addMissingContentLengthHeader(response, entity);
        response.setEntity(entity);
    }

    final long age = this.validityStrategy.getCurrentAgeSecs(entry, now);
    if (age > 0) {
        if (age >= Integer.MAX_VALUE) {
            response.setHeader(HeaderConstants.AGE, "2147483648");
        } else {
            response.setHeader(HeaderConstants.AGE, "" + ((int) age));
        }
    }

    return Proxies.enhanceResponse(response);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:32,代码来源:CachedHttpResponseGenerator.java

示例12: etagValidatorMatches

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
/**
 * Check entry against If-None-Match
 * @param request The current httpRequest being made
 * @param entry the cache entry
 * @return boolean does the etag validator match
 */
private boolean etagValidatorMatches(final HttpRequest request, final HttpCacheEntry entry) {
    final Header etagHeader = entry.getFirstHeader(HeaderConstants.ETAG);
    final String etag = (etagHeader != null) ? etagHeader.getValue() : null;
    final Header[] ifNoneMatch = request.getHeaders(HeaderConstants.IF_NONE_MATCH);
    if (ifNoneMatch != null) {
        for (final Header h : ifNoneMatch) {
            for (final HeaderElement elt : h.getElements()) {
                final String reqEtag = elt.toString();
                if (("*".equals(reqEtag) && etag != null)
                        || reqEtag.equals(etag)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:CachedResponseSuitabilityChecker.java

示例13: lastModifiedValidatorMatches

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
/**
 * Check entry against If-Modified-Since, if If-Modified-Since is in the future it is invalid as per
 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
 * @param request The current httpRequest being made
 * @param entry the cache entry
 * @param now right NOW in time
 * @return  boolean Does the last modified header match
 */
private boolean lastModifiedValidatorMatches(final HttpRequest request, final HttpCacheEntry entry, final Date now) {
    final Header lastModifiedHeader = entry.getFirstHeader(HeaderConstants.LAST_MODIFIED);
    Date lastModified = null;
    if (lastModifiedHeader != null) {
        lastModified = DateUtils.parseDate(lastModifiedHeader.getValue());
    }
    if (lastModified == null) {
        return false;
    }

    for (final Header h : request.getHeaders(HeaderConstants.IF_MODIFIED_SINCE)) {
        final Date ifModifiedSince = DateUtils.parseDate(h.getValue());
        if (ifModifiedSince != null) {
            if (ifModifiedSince.after(now) || lastModified.after(ifModifiedSince)) {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:29,代码来源:CachedResponseSuitabilityChecker.java

示例14: isNotStale

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
/**
 * Try to detect if the returned response is generated from a stale cache entry.
 * @param httpResponse the response to be checked
 * @return whether the response is stale or not
 */
private boolean isNotStale(final HttpResponse httpResponse) {
    final Header[] warnings = httpResponse.getHeaders(HeaderConstants.WARNING);
    if (warnings != null)
    {
        for (final Header warning : warnings)
        {
            /**
             * warn-codes
             * 110 = Response is stale
             * 111 = Revalidation failed
             */
            final String warningValue = warning.getValue();
            if (warningValue.startsWith("110") || warningValue.startsWith("111"))
            {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:AsynchronousValidationRequest.java

示例15: buildConditionalRequestFromVariants

import org.apache.http.client.cache.HeaderConstants; //导入依赖的package包/类
/**
 * When a {@link HttpCacheEntry} does not exist for a specific
 * {@link org.apache.http.HttpRequest} we attempt to see if an existing
 * {@link HttpCacheEntry} is appropriate by building a conditional
 * {@link org.apache.http.HttpRequest} using the variants' ETag values.
 * If no such values exist, the request is unmodified
 *
 * @param request the original request from the caller
 * @param variants
 * @return the wrapped request
 */
public HttpRequestWrapper buildConditionalRequestFromVariants(final HttpRequestWrapper request,
        final Map<String, Variant> variants) {
    final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal());
    newRequest.setHeaders(request.getAllHeaders());

    // we do not support partial content so all etags are used
    final StringBuilder etags = new StringBuilder();
    boolean first = true;
    for(final String etag : variants.keySet()) {
        if (!first) {
            etags.append(",");
        }
        first = false;
        etags.append(etag);
    }

    newRequest.setHeader(HeaderConstants.IF_NONE_MATCH, etags.toString());
    return newRequest;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:31,代码来源:ConditionalRequestBuilder.java


注:本文中的org.apache.http.client.cache.HeaderConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。