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


Java HttpResponse.getFirstHeader方法代码示例

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


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

示例1: isRedirected

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public boolean isRedirected(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");

    final int statusCode = response.getStatusLine().getStatusCode();
    final String method = request.getRequestLine().getMethod();
    final Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:23,代码来源:DefaultRedirectStrategy.java

示例2: revalidationResponseIsTooOld

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private boolean revalidationResponseIsTooOld(final HttpResponse backendResponse,
        final HttpCacheEntry cacheEntry) {
    final Header entryDateHeader = cacheEntry.getFirstHeader(HTTP.DATE_HEADER);
    final Header responseDateHeader = backendResponse.getFirstHeader(HTTP.DATE_HEADER);
    if (entryDateHeader != null && responseDateHeader != null) {
        final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
        final Date respDate = DateUtils.parseDate(responseDateHeader.getValue());
        if (entryDate == null || respDate == null) {
            // either backend response or cached entry did not have a valid
            // Date header, so we can't tell if they are out of order
            // according to the origin clock; thus we can skip the
            // unconditional retry recommended in 13.2.6 of RFC 2616.
            return false;
        }
        if (respDate.before(entryDate)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:21,代码来源:CachingExec.java

示例3: alreadyHaveNewerCacheEntry

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private boolean alreadyHaveNewerCacheEntry(final HttpHost target, final HttpRequestWrapper request,
        final HttpResponse backendResponse) {
    HttpCacheEntry existing = null;
    try {
        existing = responseCache.getCacheEntry(target, request);
    } catch (final IOException ioe) {
        // nop
    }
    if (existing == null) {
        return false;
    }
    final Header entryDateHeader = existing.getFirstHeader(HTTP.DATE_HEADER);
    if (entryDateHeader == null) {
        return false;
    }
    final Header responseDateHeader = backendResponse.getFirstHeader(HTTP.DATE_HEADER);
    if (responseDateHeader == null) {
        return false;
    }
    final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
    final Date responseDate = DateUtils.parseDate(responseDateHeader.getValue());
    if (entryDate == null || responseDate == null) {
        return false;
    }
    return responseDate.before(entryDate);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:27,代码来源:CachingExec.java

示例4: isIncompleteResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
boolean isIncompleteResponse(final HttpResponse resp, final Resource resource) {
    final int status = resp.getStatusLine().getStatusCode();
    if (status != HttpStatus.SC_OK
        && status != HttpStatus.SC_PARTIAL_CONTENT) {
        return false;
    }
    final Header hdr = resp.getFirstHeader(HTTP.CONTENT_LEN);
    if (hdr == null) {
        return false;
    }
    final int contentLength;
    try {
        contentLength = Integer.parseInt(hdr.getValue());
    } catch (final NumberFormatException nfe) {
        return false;
    }
    return (resource.length() < contentLength);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:19,代码来源:BasicHttpCache.java

示例5: expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl

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

示例6: isExplicitlyCacheable

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
protected boolean isExplicitlyCacheable(final HttpResponse response) {
    if (response.getFirstHeader(HeaderConstants.EXPIRES) != null) {
        return true;
    }
    final String[] cacheableParams = { HeaderConstants.CACHE_CONTROL_MAX_AGE, "s-maxage",
            HeaderConstants.CACHE_CONTROL_MUST_REVALIDATE,
            HeaderConstants.CACHE_CONTROL_PROXY_REVALIDATE,
            HeaderConstants.PUBLIC
    };
    return hasCacheControlParameterFrom(response, cacheableParams);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:12,代码来源:ResponseCachingPolicy.java

示例7: from1_0Origin

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private boolean from1_0Origin(final HttpResponse response) {
    final Header via = response.getFirstHeader(HeaderConstants.VIA);
    if (via != null) {
        for(final HeaderElement elt : via.getElements()) {
            final String proto = elt.toString().split("\\s")[0];
            if (proto.contains("/")) {
                return proto.equals("HTTP/1.0");
            } else {
                return proto.equals("1.0");
            }
        }
    }
    return HttpVersion.HTTP_1_0.equals(response.getProtocolVersion());
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:15,代码来源:ResponseCachingPolicy.java

示例8: ensure200ForOPTIONSRequestWithNoBodyHasContentLengthZero

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private void ensure200ForOPTIONSRequestWithNoBodyHasContentLengthZero(final HttpRequest request,
        final HttpResponse response) {
    if (!request.getRequestLine().getMethod().equalsIgnoreCase(HeaderConstants.OPTIONS_METHOD)) {
        return;
    }

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        return;
    }

    if (response.getFirstHeader(HTTP.CONTENT_LEN) == null) {
        response.addHeader(HTTP.CONTENT_LEN, "0");
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:15,代码来源:ResponseProtocolCompliance.java

示例9: entryAndResponseHaveDateHeader

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private boolean entryAndResponseHaveDateHeader(final HttpCacheEntry entry, final HttpResponse response) {
    if (entry.getFirstHeader(HTTP.DATE_HEADER) != null
            && response.getFirstHeader(HTTP.DATE_HEADER) != null) {
        return true;
    }

    return false;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:9,代码来源:CacheEntryUpdater.java

示例10: getContentLocationURL

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private URL getContentLocationURL(final URL reqURL, final HttpResponse response) {
    final Header clHeader = response.getFirstHeader("Content-Location");
    if (clHeader == null) {
        return null;
    }
    final String contentLocation = clHeader.getValue();
    final URL canonURL = getAbsoluteURL(contentLocation);
    if (canonURL != null) {
        return canonURL;
    }
    return getRelativeURL(reqURL, contentLocation);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:13,代码来源:CacheInvalidator.java

示例11: getLocationURL

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private URL getLocationURL(final URL reqURL, final HttpResponse response) {
    final Header clHeader = response.getFirstHeader("Location");
    if (clHeader == null) {
        return null;
    }
    final String location = clHeader.getValue();
    final URL canonURL = getAbsoluteURL(location);
    if (canonURL != null) {
        return canonURL;
    }
    return getRelativeURL(reqURL, location);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:13,代码来源:CacheInvalidator.java

示例12: responseAndEntryEtagsDiffer

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private boolean responseAndEntryEtagsDiffer(final HttpResponse response,
        final HttpCacheEntry entry) {
    final Header entryEtag = entry.getFirstHeader(HeaderConstants.ETAG);
    final Header responseEtag = response.getFirstHeader(HeaderConstants.ETAG);
    if (entryEtag == null || responseEtag == null) {
        return false;
    }
    return (!entryEtag.getValue().equals(responseEtag.getValue()));
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:10,代码来源:CacheInvalidator.java

示例13: responseDateOlderThanEntryDate

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
private boolean responseDateOlderThanEntryDate(final HttpResponse response,
        final HttpCacheEntry entry) {
    final Header entryDateHeader = entry.getFirstHeader(HTTP.DATE_HEADER);
    final Header responseDateHeader = response.getFirstHeader(HTTP.DATE_HEADER);
    if (entryDateHeader == null || responseDateHeader == null) {
        /* be conservative; should probably flush */
        return false;
    }
    final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
    final Date responseDate = DateUtils.parseDate(responseDateHeader.getValue());
    if (entryDate == null || responseDate == null) {
        return false;
    }
    return responseDate.before(entryDate);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:16,代码来源:CacheInvalidator.java

示例14: process

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(response, "HTTP response");

    final HttpCoreContext corecontext = HttpCoreContext.adapt(context);

    // Always drop connection after certain type of responses
    final int status = response.getStatusLine().getStatusCode();
    if (status == HttpStatus.SC_BAD_REQUEST ||
            status == HttpStatus.SC_REQUEST_TIMEOUT ||
            status == HttpStatus.SC_LENGTH_REQUIRED ||
            status == HttpStatus.SC_REQUEST_TOO_LONG ||
            status == HttpStatus.SC_REQUEST_URI_TOO_LONG ||
            status == HttpStatus.SC_SERVICE_UNAVAILABLE ||
            status == HttpStatus.SC_NOT_IMPLEMENTED) {
        response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        return;
    }
    final Header explicit = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
    if (explicit != null && HTTP.CONN_CLOSE.equalsIgnoreCase(explicit.getValue())) {
        // Connection persistence explicitly disabled
        return;
    }
    // Always drop connection for HTTP/1.0 responses and below
    // if the content body cannot be correctly delimited
    final HttpEntity entity = response.getEntity();
    if (entity != null) {
        final ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
        if (entity.getContentLength() < 0 &&
                (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0))) {
            response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
            return;
        }
    }
    // Drop connection if requested by the client or request was <= 1.0
    final HttpRequest request = corecontext.getRequest();
    if (request != null) {
        final Header header = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
        if (header != null) {
            response.setHeader(HTTP.CONN_DIRECTIVE, header.getValue());
        } else if (request.getProtocolVersion().lessEquals(HttpVersion.HTTP_1_0)) {
            response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:46,代码来源:ResponseConnControl.java

示例15: getLocationURI

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    final String location = locationHeader.getValue();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location);

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            Asserts.notNull(target, "Target host");
            final URI requestURI = new URI(request.getRequestLine().getUri());
            final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocations redirectLocations = (RedirectLocations) clientContext.getAttribute(
            HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocations();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:61,代码来源:DefaultRedirectStrategy.java


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