code: private boolean isAuthenticationNeeded(final HttpMethod method) {
          method.getHostAuthState().setAuthRequested(
                  method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED);
          method.getProxyAuthState().setAuthRequested(
                  method.getStatusCode() == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED);
          if (method.getHostAuthState().isAuthRequested() || 
              method.getProxyAuthState().isAuthRequested()) {
              LOG.debug("Authorization required");
              if (method.getDoAuthentication()) { //process authentication response
                  return true;
              } else { //let the client handle the authenticaiton
                  LOG.info("Authentication requested but doAuthentication is "
                          + "disabled");
                  return false;
              }
          } else {
              return false;
          }
      }
docs: Tests if the {@link HttpMethod method} requires authentication.
  
  @param method HTTP method
  
  @return boolean <tt>true</tt> if a retry is needed, <tt>false</tt> otherwise.