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


Java HttpRequest.getHeaders方法代码示例

本文整理汇总了Java中ch.boye.httpclientandroidlib.HttpRequest.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.getHeaders方法的具体用法?Java HttpRequest.getHeaders怎么用?Java HttpRequest.getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.boye.httpclientandroidlib.HttpRequest的用法示例。


在下文中一共展示了HttpRequest.getHeaders方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stripOtherFreshnessDirectivesWithNoCache

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的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:mozilla-mobile,项目名称:FirefoxData-android,代码行数:20,代码来源:RequestProtocolCompliance.java

示例2: etagValidatorMatches

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的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:mozilla-mobile,项目名称:FirefoxData-android,代码行数:24,代码来源:CachedResponseSuitabilityChecker.java

示例3: lastModifiedValidatorMatches

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的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:mozilla-mobile,项目名称:FirefoxData-android,代码行数:29,代码来源:CachedResponseSuitabilityChecker.java

示例4: isServableFromCache

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的package包/类
/**
 * Determines if an HttpRequest can be served from the cache.
 *
 * @param request
 *            an HttpRequest
 * @return boolean Is it possible to serve this request from cache
 */
public boolean isServableFromCache(final HttpRequest request) {
    final String method = request.getRequestLine().getMethod();

    final ProtocolVersion pv = request.getRequestLine().getProtocolVersion();
    if (HttpVersion.HTTP_1_1.compareToVersion(pv) != 0) {
        log.trace("non-HTTP/1.1 request was not serveable from cache");
        return false;
    }

    if (!method.equals(HeaderConstants.GET_METHOD)) {
        log.trace("non-GET request was not serveable from cache");
        return false;
    }

    if (request.getHeaders(HeaderConstants.PRAGMA).length > 0) {
        log.trace("request with Pragma header was not serveable from cache");
        return false;
    }

    final Header[] cacheControlHeaders = request.getHeaders(HeaderConstants.CACHE_CONTROL);
    for (final Header cacheControl : cacheControlHeaders) {
        for (final HeaderElement cacheControlElement : cacheControl.getElements()) {
            if (HeaderConstants.CACHE_CONTROL_NO_STORE.equalsIgnoreCase(cacheControlElement
                    .getName())) {
                log.trace("Request with no-store was not serveable from cache");
                return false;
            }

            if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equalsIgnoreCase(cacheControlElement
                    .getName())) {
                log.trace("Request with no-cache was not serveable from cache");
                return false;
            }
        }
    }

    log.trace("Request was serveable from cache");
    return true;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:47,代码来源:CacheableRequestPolicy.java

示例5: add100ContinueHeaderIfMissing

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的package包/类
private void add100ContinueHeaderIfMissing(final HttpRequest request) {
    boolean hasHeader = false;

    for (final Header h : request.getHeaders(HTTP.EXPECT_DIRECTIVE)) {
        for (final HeaderElement elt : h.getElements()) {
            if (HTTP.EXPECT_CONTINUE.equalsIgnoreCase(elt.getName())) {
                hasHeader = true;
            }
        }
    }

    if (!hasHeader) {
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:16,代码来源:RequestProtocolCompliance.java

示例6: requestContainsNoCacheDirectiveWithFieldName

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的package包/类
private RequestProtocolError requestContainsNoCacheDirectiveWithFieldName(final HttpRequest request) {
    for(final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
        for(final HeaderElement elt : h.getElements()) {
            if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equalsIgnoreCase(elt.getName())
                && elt.getValue() != null) {
                return RequestProtocolError.NO_CACHE_DIRECTIVE_WITH_FIELD_NAME;
            }
        }
    }
    return null;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:12,代码来源:RequestProtocolCompliance.java

示例7: isResponseCacheable

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的package包/类
/**
 * Determine if the {@link HttpResponse} gotten from the origin is a
 * cacheable response.
 *
 * @param request the {@link HttpRequest} that generated an origin hit
 * @param response the {@link HttpResponse} from the origin
 * @return <code>true</code> if response is cacheable
 */
public boolean isResponseCacheable(final HttpRequest request, final HttpResponse response) {
    if (requestProtocolGreaterThanAccepted(request)) {
        log.debug("Response was not cacheable.");
        return false;
    }

    final String[] uncacheableRequestDirectives = { HeaderConstants.CACHE_CONTROL_NO_STORE };
    if (hasCacheControlParameterFrom(request,uncacheableRequestDirectives)) {
        return false;
    }

    if (request.getRequestLine().getUri().contains("?")) {
        if (neverCache1_0ResponsesWithQueryString && from1_0Origin(response)) {
            log.debug("Response was not cacheable as it had a query string.");
            return false;
        } else if (!isExplicitlyCacheable(response)) {
            log.debug("Response was not cacheable as it is missing explicit caching headers.");
            return false;
        }
    }

    if (expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl(response)) {
        return false;
    }

    if (sharedCache) {
        final Header[] authNHeaders = request.getHeaders(HeaderConstants.AUTHORIZATION);
        if (authNHeaders != null && authNHeaders.length > 0
                && !hasCacheControlParameterFrom(response, AUTH_CACHEABLE_PARAMS)) {
            return false;
        }
    }

    final String method = request.getRequestLine().getMethod();
    return isResponseCacheable(method, response);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:45,代码来源:ResponseCachingPolicy.java

示例8: getMaxStale

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的package包/类
private long getMaxStale(final HttpRequest request) {
    long maxstale = -1;
    for(final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
        for(final HeaderElement elt : h.getElements()) {
            if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) {
                if ((elt.getValue() == null || "".equals(elt.getValue().trim()))
                        && maxstale == -1) {
                    maxstale = Long.MAX_VALUE;
                } else {
                    try {
                        long val = Long.parseLong(elt.getValue());
                        if (val < 0) {
                            val = 0;
                        }
                        if (maxstale == -1 || val < maxstale) {
                            maxstale = val;
                        }
                    } catch (final NumberFormatException nfe) {
                        // err on the side of preserving semantic transparency
                        maxstale = 0;
                    }
                }
            }
        }
    }
    return maxstale;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:28,代码来源:CachedResponseSuitabilityChecker.java

示例9: hasValidDateField

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的package包/类
private boolean hasValidDateField(final HttpRequest request, final String headerName) {
    for(final Header h : request.getHeaders(headerName)) {
        final Date date = DateUtils.parseDate(h.getValue());
        return date != null;
    }
    return false;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:8,代码来源:CachedResponseSuitabilityChecker.java


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