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


Java HttpResponse.setHeaders方法代码示例

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


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

示例1: generateResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * If I was able to use a {@link CacheEntity} to response to the {@link ch.boye.httpclientandroidlib.HttpRequest} then
 * generate an {@link HttpResponse} based on the cache entry.
 * @param entry
 *            {@link CacheEntity} to transform into an {@link HttpResponse}
 * @return {@link HttpResponse} that was constructed
 */
CloseableHttpResponse generateResponse(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 (entry.getResource() != null) {
        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:mozilla-mobile,项目名称:FirefoxData-android,代码行数:33,代码来源:CachedHttpResponseGenerator.java

示例2: getReconstructedResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
CloseableHttpResponse getReconstructedResponse() throws IOException {
    ensureConsumed();
    final HttpResponse reconstructed = new BasicHttpResponse(response.getStatusLine());
    reconstructed.setHeaders(response.getAllHeaders());

    final CombinedEntity combinedEntity = new CombinedEntity(resource, instream);
    final HttpEntity entity = response.getEntity();
    if (entity != null) {
        combinedEntity.setContentType(entity.getContentType());
        combinedEntity.setContentEncoding(entity.getContentEncoding());
        combinedEntity.setChunked(entity.isChunked());
    }
    reconstructed.setEntity(combinedEntity);
    return (CloseableHttpResponse) Proxy.newProxyInstance(
            ResponseProxyHandler.class.getClassLoader(),
            new Class<?>[] { CloseableHttpResponse.class },
            new ResponseProxyHandler(reconstructed) {

                @Override
                public void close() throws IOException {
                    response.close();
                }

            });
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:26,代码来源:SizeLimitedResponseReader.java


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