简体   繁体   中英

What does setExpectContinueEnabled mean?

I am using Apache HttpClient in our project by using PoolingHttpClientConnectionManager . I understood most of the property but I was confuse what does setExpectContinueEnabled mean? Does this be kept always true or false ? 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. "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. 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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