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

HttpClientBuilder placing last HttpRequestInterceptor first

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.0
    • 5.0.2
    • HttpClient (classic)
    • None

    Description

      With the following:

      CloseableHttpClient client = HttpClients.custom()
          .addRequestInterceptorFirst((request, entity, context) -> {
              System.out.println("This should be first");
          })
          .addRequestInterceptorLast((request, entity, context) -> {
              System.out.println("This should be last");
          })
          .build();
      
      client.execute(new HttpGet("http://www.example.com"));
      

      Result:

      This should be last
      This should be first
      

      In org.apache.hc.client5.http.impl.classic.HttpClientBuilder

      lines 830-832 adds the interceptor to the start of the list instead of the end.

      if (entry.postion == RequestInterceptorEntry.Postion.LAST) {
          b.addFirst(entry.interceptor);
      }
      

      This should probably be the following:

      if (entry.postion == RequestInterceptorEntry.Postion.LAST) {
          b.addLast(entry.interceptor); 
      }
      

       

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            john.enters@gmail.com John Enters
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 20m
                20m
                Remaining:
                Remaining Estimate - 20m
                20m
                Logged:
                Time Spent - Not Specified
                Not Specified