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


Java HttpRequest.removeHeaders方法代码示例

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


在下文中一共展示了HttpRequest.removeHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: decrementOPTIONSMaxForwardsIfGreaterThen0

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

    final Header maxForwards = request.getFirstHeader(HeaderConstants.MAX_FORWARDS);
    if (maxForwards == null) {
        return;
    }

    request.removeHeaders(HeaderConstants.MAX_FORWARDS);
    final int currentMaxForwards = Integer.parseInt(maxForwards.getValue());

    request.setHeader(HeaderConstants.MAX_FORWARDS, Integer.toString(currentMaxForwards - 1));
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:16,代码来源:RequestProtocolCompliance.java

示例3: process

import ch.boye.httpclientandroidlib.HttpRequest; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    if (request instanceof HttpEntityEnclosingRequest) {
        if (this.overwrite) {
            request.removeHeaders(HTTP.TRANSFER_ENCODING);
            request.removeHeaders(HTTP.CONTENT_LEN);
        } else {
            if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
                throw new ProtocolException("Transfer-encoding header already present");
            }
            if (request.containsHeader(HTTP.CONTENT_LEN)) {
                throw new ProtocolException("Content-Length header already present");
            }
        }
        final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
        final HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
        if (entity == null) {
            request.addHeader(HTTP.CONTENT_LEN, "0");
            return;
        }
        // Must specify a transfer encoding or a content length
        if (entity.isChunked() || entity.getContentLength() < 0) {
            if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
                throw new ProtocolException(
                        "Chunked transfer encoding not allowed for " + ver);
            }
            request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        } else {
            request.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
        }
        // Specify a content type if known
        if (entity.getContentType() != null && !request.containsHeader(
                HTTP.CONTENT_TYPE )) {
            request.addHeader(entity.getContentType());
        }
        // Specify a content encoding if known
        if (entity.getContentEncoding() != null && !request.containsHeader(
                HTTP.CONTENT_ENCODING)) {
            request.addHeader(entity.getContentEncoding());
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:44,代码来源:RequestContent.java


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