Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
4.3.2
-
None
Description
When HttpClient retries a POST request after receiving 503 (service temporary unavailable), ClientProtocolException occurs. On second request, Content-Length header is already set and the RequestContent created by HttpClientBuilder doesn't allow overriding it.
There's a workaround:
HttpClientBuilder builder = HttpClientBuilder.create(); builder.setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(2, 100)); builder.addInterceptorFirst(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if (request.containsHeader(HTTP.CONTENT_LEN)) { request.removeHeaders(HTTP.CONTENT_LEN); } } });
I think HttpClientBuilder should provide an option like this:
HttpClientBuilder.create()
.setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy()
.enableOverrideContentLength()
...