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


Java HttpResponse.getHeaders方法代码示例

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


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

示例1: isNotStale

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

示例2: getChallenges

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public Map<String, Header> getChallenges(
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(response, "HTTP response");
    final Header[] headers = response.getHeaders(AUTH.WWW_AUTH);
    return parseChallenges(headers);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:8,代码来源:DefaultTargetAuthenticationHandler.java

示例3: isExplicitlyNonCacheable

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
protected boolean isExplicitlyNonCacheable(final HttpResponse response) {
    final Header[] cacheControlHeaders = response.getHeaders(HeaderConstants.CACHE_CONTROL);
    for (final Header header : cacheControlHeaders) {
        for (final HeaderElement elem : header.getElements()) {
            if (HeaderConstants.CACHE_CONTROL_NO_STORE.equals(elem.getName())
                    || HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elem.getName())
                    || (sharedCache && HeaderConstants.PRIVATE.equals(elem.getName()))) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:14,代码来源:ResponseCachingPolicy.java

示例4: getChallenges

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public Map<String, Header> getChallenges(
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(response, "HTTP response");
    final Header[] headers = response.getHeaders(AUTH.PROXY_AUTH);
    return parseChallenges(headers);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:8,代码来源:DefaultProxyAuthenticationHandler.java

示例5: isResponseCacheable

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * Determines if an HttpResponse can be cached.
 *
 * @param httpMethod What type of request was this, a GET, PUT, other?
 * @param response The origin response
 * @return <code>true</code> if response is cacheable
 */
public boolean isResponseCacheable(final String httpMethod, final HttpResponse response) {
    boolean cacheable = false;

    if (!HeaderConstants.GET_METHOD.equals(httpMethod)) {
        log.debug("Response was not cacheable.");
        return false;
    }

    final int status = response.getStatusLine().getStatusCode();
    if (cacheableStatuses.contains(status)) {
        // these response codes MAY be cached
        cacheable = true;
    } else if (uncacheableStatuses.contains(status)) {
        return false;
    } else if (unknownStatusCode(status)) {
        // a response with an unknown status code MUST NOT be
        // cached
        return false;
    }

    final Header contentLength = response.getFirstHeader(HTTP.CONTENT_LEN);
    if (contentLength != null) {
        final int contentLengthValue = Integer.parseInt(contentLength.getValue());
        if (contentLengthValue > this.maxObjectSizeBytes) {
            return false;
        }
    }

    final Header[] ageHeaders = response.getHeaders(HeaderConstants.AGE);

    if (ageHeaders.length > 1) {
        return false;
    }

    final Header[] expiresHeaders = response.getHeaders(HeaderConstants.EXPIRES);

    if (expiresHeaders.length > 1) {
        return false;
    }

    final Header[] dateHeaders = response.getHeaders(HTTP.DATE_HEADER);

    if (dateHeaders.length != 1) {
        return false;
    }

    final Date date = DateUtils.parseDate(dateHeaders[0].getValue());
    if (date == null) {
        return false;
    }

    for (final Header varyHdr : response.getHeaders(HeaderConstants.VARY)) {
        for (final HeaderElement elem : varyHdr.getElements()) {
            if ("*".equals(elem.getName())) {
                return false;
            }
        }
    }

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

    return (cacheable || isExplicitlyCacheable(response));
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:73,代码来源:ResponseCachingPolicy.java


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