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


Java HttpResponse.setHeader方法代码示例

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


在下文中一共展示了HttpResponse.setHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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 int status = response.getStatusLine().getStatusCode();
    if ((status >= HttpStatus.SC_OK) &&
        !response.containsHeader(HTTP.DATE_HEADER)) {
        final String httpdate = DATE_GENERATOR.getCurrentDate();
        response.setHeader(HTTP.DATE_HEADER, httpdate);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:11,代码来源:ResponseDate.java

示例3: generateIncompleteResponseError

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
CloseableHttpResponse generateIncompleteResponseError(
        final HttpResponse response, final Resource resource) {
    final int contentLength = Integer.parseInt(response.getFirstHeader(HTTP.CONTENT_LEN).getValue());
    final HttpResponse error =
        new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_GATEWAY, "Bad Gateway");
    error.setHeader("Content-Type","text/plain;charset=UTF-8");
    final String msg = String.format("Received incomplete response " +
            "with Content-Length %d but actual body length %d",
            contentLength, resource.length());
    final byte[] msgBytes = msg.getBytes();
    error.setHeader("Content-Length", Integer.toString(msgBytes.length));
    error.setEntity(new ByteArrayEntity(msgBytes));
    return Proxies.enhanceResponse(error);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:15,代码来源:BasicHttpCache.java

示例4: 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


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