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

Single cookie header should be sent for multiple cookies

    XMLWordPrintableJSON

Details

    Description

      Single cookie header should be sent for multiple cookies

      Use case

      When Cookie header is added explicitly using setHeader() method and there exists multiple cookies in cookie store (BasicCookieStore), then for this use case two Cookie headers are sent by HttpClient.

      Expectation - Single Cookie header should be sent by Apache HttpClient where all cookies should be separated by semi-colon

      Actual - Two Cookie headers are sent by Apache HttpClient, where in cookie set using setHeader is sent as one cookie Header and cookies in BasicCookieStore are sent in another Cookie header wherein value is all cookies separates by semi-colon.

       

      Steps to reproduce -

      1. Setup two microservices
      2. 1st microservice will set custom Cookie header as part of API request to 2nd micro service.
      3. 2nd microservice will respond back with two Set-Cookie headers 
      4. First time when call is made from 1st micro service to 2nd micro service only custom cookie header will be sent and BasicCookieStore on 1st microservice will be updated with cookies that we got from 2nd microservice
      5. Second time when call is made from 1st micro service to 2nd micro service both custom cookie and cookies from BasicCookieStore will be sent as separate Cookie headers.

       

      2024-06-18 09:45:28.074 DEBUG 3540 --- [nio-8090-exec-7] org.apache.hc.client5.http.headers       : http-outgoing-1 >> GET /demo-service-two/test HTTP/1.1
      2024-06-18 09:45:28.074 DEBUG 3540 --- [nio-8090-exec-7] org.apache.hc.client5.http.headers       : http-outgoing-1 >> Cookie: MyCustomCookie=QWERTY
      2024-06-18 09:45:28.074 DEBUG 3540 --- [nio-8090-exec-7] org.apache.hc.client5.http.headers       : http-outgoing-1 >> Accept-Encoding: gzip, x-gzip, deflate
      2024-06-18 09:45:28.075 DEBUG 3540 --- [nio-8090-exec-7] org.apache.hc.client5.http.headers       : http-outgoing-1 >> Host: localhost:8091
      2024-06-18 09:45:28.075 DEBUG 3540 --- [nio-8090-exec-7] org.apache.hc.client5.http.headers       : http-outgoing-1 >> Connection: keep-alive
      2024-06-18 09:45:28.075 DEBUG 3540 --- [nio-8090-exec-7] org.apache.hc.client5.http.headers       : http-outgoing-1 >> User-Agent: Apache-HttpClient/5.1.3 (Java/17.0.8)
      2024-06-18 09:45:28.075 DEBUG 3540 --- [nio-8090-exec-7] org.apache.hc.client5.http.headers       : http-outgoing-1 >> Cookie: ServiceTwoSession1=POIUY; ServiceTwoSession2=ZXCVB 

       

      Attachments

        1. DemoServiceOneController.java
          2 kB
          Nikhil Chaudhari
        2. DemoServiceOneLogs.txt
          13 kB
          Nikhil Chaudhari
        3. DemoServiceTwoController.java
          0.7 kB
          Nikhil Chaudhari

        Activity

          People

            Unassigned Unassigned
            nvchaudhari1991 Nikhil Chaudhari
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: