Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1456

ClientProtocolException occurs when retries after receiving 503

    XMLWordPrintableJSON

Details

    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()
       ...
      

      Attachments

        1. HTTPCLIENT-1456.patch
          1 kB
          Liu Kumai

        Activity

          People

            Unassigned Unassigned
            kuma Liu Kumai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: