简体   繁体   English

setExpectContinueEnabled是什么意思?

[英]What does setExpectContinueEnabled mean?

I am using Apache HttpClient in our project by using PoolingHttpClientConnectionManager . 我通过使用PoolingHttpClientConnectionManager在我们的项目中使用Apache HttpClient。 I understood most of the property but I was confuse what does setExpectContinueEnabled mean? 我了解大多数属性,但感到困惑setExpectContinueEnabled是什么意思? Does this be kept always true or false ? 是否始终将其设为truefalse Can anyone provide some explanation what does it mean in general? 谁能提供一些解释,这通常意味着什么?

    private ClientHttpRequestFactory clientHttpRequestFactory() {
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(1000).setConnectTimeout(1000)
                .setSocketTimeout(1000).setStaleConnectionCheckEnabled(false).build();

        SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();

        PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager();
        poolingHttpClientConnectionManager.setMaxTotal(800);
        poolingHttpClientConnectionManager.setDefaultMaxPerRoute(700);

        CloseableHttpClient httpClientBuilder = HttpClientBuilder.create()
                .setConnectionManager(poolingHttpClientConnectionManager).setDefaultRequestConfig(requestConfig)
                .setDefaultSocketConfig(socketConfig).build();

        requestFactory.setHttpClient(httpClientBuilder);
        return requestFactory;
    }

Methods of the form setXyzEnabled set a flag that controls whether an optional feature is used/allowed or not, in this case for request(s) using the RequestConfig. setXyzEnabled形式的方法设置一个标志,该标志控制是否使用/不允许使用可选功能,在这种情况下,该功能用于使用RequestConfig的请求。 "Expect Continue" is an option in the HTTP/1.1 protocol where the client sends only the header of a request and waits for a response, normally "100 Continue", before sending the body. “期望继续”是HTTP / 1.1协议中的一个选项,客户端在发送正文之前,客户端仅发送请求的标头并等待响应(通常为“ 100继续”)。 This allows it to skip sending the body if the server determines an error based (only) on the header. 如果服务器(仅)基于报头确定错误,则允许它跳过发送正文。

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.20 (request) and http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3 (response) or more picturesquely http://httpstatusdogs.com/100-continue . 请参阅http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.20 (请求)和http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8。 2.3 (响应)或更精美的图片http://httpstatusdogs.com/100-continue

This is a bad idea if your server doesn't, or doesn't always, or isn't definitely known to, support Continue. 如果您的服务器不支持或不总是支持或不完全支持继续,则这是一个坏主意。 It may be a good idea if your server(s) definitely does support Continue and you have requests with large or huge bodies that the server is significantly likely to reject. 如果您的服务器确实支持继续,并且您的请求具有很大或很大的请求,则服务器很可能会拒绝,这可能是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM