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

HttpClient does not handle cookies during authentication



    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 4.3.6
    • Fix Version/s: None
    • Component/s: HttpClient (classic)
    • Labels:


      When upgrading from HTTPClient version 4.2.x to 4.3.6 we recognized that cookies are no longer handled during e.g. DIGEST authentication. This causes the authentication to fail in our cluster environment where a cookie is returned by the load balancer in front used to ensure that all request which are part of the DIGEST handshake will be routed to the same cluster instance (which is crucial for the handshake to succeed!).

      From top of my head I remember to have seen a comment somewhere which stated that cookies are assumed to be issued by a server after authentication succeeded.
      From our point of view this assumption is not valid as mentioned before.

      As a workaround we registered a custom target authentication strategy implementation as follows:

              public boolean isAuthenticationRequested(HttpHost authhost, HttpResponse response, HttpContext context) {
                  final boolean isAuthenticationRequired = super.isAuthenticationRequested(authhost, response, context);
                  if (isAuthenticationRequired) {
                      // In case authentication is required store any cookies already set by the server in order to cope with
                      // situations where the load balancer adds a cookie for the DIGEST authentication since the new HTTP
                      // Client
                      // library does not foresee this situation by default
                      try {
                          new ResponseProcessCookies().process(response, context);
                          final HttpRequest request = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
                          if (request != null) {
                              new RequestAddCookies().process(request, context);
                      } catch (final Exception e) {
                          LOG.error("Custom handling of load balancer session cookies during authentication failed: "
                                  + e.getMessage(), e);
                  return isAuthenticationRequired;

      which is more a kind of hack...

      Please check whether it is possible to add support for cookies during authentication again so that we do not have to apply the workaround again for each new version.

      Thank you!

      Kind regards,


          Issue Links



              • Assignee:
                cak_at_work Carsten Kaiser
              • Votes:
                0 Vote for this issue
                1 Start watching this issue


                • Created: