org.apache.hc.client5.http.protocol

## Class HttpClientContext

- java.lang.Object
- - org.apache.hc.core5.http.protocol.HttpCoreContext
  - - org.apache.hc.client5.http.protocol.HttpClientContext

All Implemented Interfaces:
  org.apache.hc.core5.http.protocol.HttpContext

    public class HttpClientContext
    extends org.apache.hc.core5.http.protocol.HttpCoreContext

Client execution `HttpContext`. This class can be re-used for multiple consecutive logically related request executions that represent a single communication session. This context may not be used concurrently.

IMPORTANT: This class is NOT thread-safe and MUST NOT be used concurrently by multiple message exchanges.

Since:
  4.3

### Field Summary

Fields
`static String` `AUTH_CACHE` Deprecated. Use getter methods
`static String` `AUTH_EXCHANGE_MAP` Deprecated. Use getter methods
`static String` `AUTHSCHEME_REGISTRY` Deprecated. Use getter methods
`static String` `COOKIE_ORIGIN` Deprecated. Use getter methods
`static String` `COOKIE_SPEC` Deprecated. Use getter methods
`static String` `COOKIE_STORE` Deprecated. Use getter methods
`static String` `COOKIESPEC_REGISTRY` Deprecated. Use getter methods
`static String` `CREDS_PROVIDER` Deprecated. Use getter methods
`static String` `EXCHANGE_ID` Deprecated. Use getter methods
`static String` `HTTP_ROUTE` Deprecated. Use getter methods
`static String` `REDIRECT_LOCATIONS` Deprecated. Use getter methods
`static String` `REQUEST_CONFIG` Deprecated. Use getter methods
`static String` `USER_TOKEN` Deprecated. Use getter methods

### Fields inherited from class org.apache.hc.core5.http.protocol.HttpCoreContext

`CONNECTION_ENDPOINT, HTTP_REQUEST, HTTP_RESPONSE, SSL_SESSION`

### Fields inherited from interface org.apache.hc.core5.http.protocol.HttpContext

`RESERVED_PREFIX`

### Constructor Summary

Constructors
Constructor and Description
`HttpClientContext()`
`HttpClientContext(org.apache.hc.core5.http.protocol.HttpContext context)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
`static HttpClientContext` `adapt(org.apache.hc.core5.http.protocol.HttpContext context)` Deprecated. Use `castOrCreate(HttpContext)`.
`static HttpClientContext` `cast(org.apache.hc.core5.http.protocol.HttpContext context)` Casts the given generic `HttpContext` as `HttpClientContext`.
`static HttpClientContext` `castOrCreate(org.apache.hc.core5.http.protocol.HttpContext context)` Casts the given generic `HttpContext` as `HttpClientContext` or creates new `HttpClientContext` if the given context is null.
`static HttpClientContext` `create()`
`AuthCache` `getAuthCache()` Represents a `AuthCache` used in the context of the request execution.
`AuthExchange` `getAuthExchange(org.apache.hc.core5.http.HttpHost host)`
`Map<org.apache.hc.core5.http.HttpHost,AuthExchange>` `getAuthExchanges()` Represents a map of `AuthExchange`s performed in the context of the request execution.
`org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory>` `getAuthSchemeRegistry()` Represents a `AuthSchemeFactory` registry used in the context of the request execution.
`CookieOrigin` `getCookieOrigin()` Represents a `CookieOrigin` produced in the context of request execution.
`CookieSpec` `getCookieSpec()` Represents a `CookieSpec` chosen in the context of request execution.
`org.apache.hc.core5.http.config.Lookup<CookieSpecFactory>` `getCookieSpecRegistry()` Represents a `CookieSpecFactory` registry used in the context of the request execution.
`CookieStore` `getCookieStore()` Represents a `CookieStore` used in the context of the request execution.
`CredentialsProvider` `getCredentialsProvider()` Represents a `CredentialsProvider` registry used in the context of the request execution.
`String` `getExchangeId()` Represents an identifier generated for the current message exchange executed in the given context.
`RouteInfo` `getHttpRoute()` Represents current route used to execute message exchanges.
`RedirectLocations` `getRedirectLocations()` Represents a collection of all redirects executed in the context of request execution.
`RequestConfig` `getRequestConfig()` Represents an `used` in the context of the request execution.
`RequestConfig` `getRequestConfigOrDefault()` Returns `RequestConfig` set in the context or `RequestConfig.DEFAULT` if not explicitly set in the context.
`Object` `getUserToken()` Represents an arbitrary user token that identifies the user in the context of the request execution.
`<T> T` `getUserToken(Class<T> clazz)` Deprecated. Use `getUserToken()`
`void` `resetAuthExchange(org.apache.hc.core5.http.HttpHost host, AuthScheme authScheme)`
`void` `setAuthCache(AuthCache authCache)`
`void` `setAuthExchange(org.apache.hc.core5.http.HttpHost host, AuthExchange authExchange)`
`void` `setAuthSchemeRegistry(org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> lookup)`
`void` `setCookieOrigin(CookieOrigin cookieOrigin)`
`void` `setCookieSpec(CookieSpec cookieSpec)`
`void` `setCookieSpecRegistry(org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> lookup)`
`void` `setCookieStore(CookieStore cookieStore)`
`void` `setCredentialsProvider(CredentialsProvider credentialsProvider)`
`void` `setExchangeId(String exchangeId)`
`void` `setRedirectLocations(RedirectLocations redirectLocations)`
`void` `setRequestConfig(RequestConfig requestConfig)`
`void` `setRoute(HttpRoute route)`
`void` `setUserToken(Object userToken)`

### Methods inherited from class org.apache.hc.core5.http.protocol.HttpCoreContext

`getAttribute, getAttribute, getEndpointDetails, getProtocolVersion, getRequest, getResponse, getSSLSession, removeAttribute, setAttribute, setEndpointDetails, setProtocolVersion, setRequest, setResponse, setSSLSession, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### HTTP_ROUTE

    @Deprecated
    public static final String HTTP_ROUTE

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### REDIRECT_LOCATIONS

    @Deprecated
    public static final String REDIRECT_LOCATIONS

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### COOKIESPEC_REGISTRY

    @Deprecated
    public static final String COOKIESPEC_REGISTRY

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### COOKIE_SPEC

    @Deprecated
    public static final String COOKIE_SPEC

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### COOKIE_ORIGIN

    @Deprecated
    public static final String COOKIE_ORIGIN

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### COOKIE_STORE

    @Deprecated
    public static final String COOKIE_STORE

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### CREDS_PROVIDER

    @Deprecated
    public static final String CREDS_PROVIDER

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### AUTH_CACHE

    @Deprecated
    public static final String AUTH_CACHE

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### AUTH_EXCHANGE_MAP

    @Deprecated
    public static final String AUTH_EXCHANGE_MAP

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### USER_TOKEN

    @Deprecated
    public static final String USER_TOKEN

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### AUTHSCHEME_REGISTRY

    @Deprecated
    public static final String AUTHSCHEME_REGISTRY

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### REQUEST_CONFIG

    @Deprecated
    public static final String REQUEST_CONFIG

Deprecated. Use getter methods

See Also:
  Constant Field Values

#### EXCHANGE_ID

    @Deprecated
    public static final String EXCHANGE_ID

Deprecated. Use getter methods

See Also:
  Constant Field Values

### Constructor Detail

#### HttpClientContext

    public HttpClientContext(org.apache.hc.core5.http.protocol.HttpContext context)

#### HttpClientContext

    public HttpClientContext()

### Method Detail

#### adapt

    @Deprecated
    public static HttpClientContext adapt(org.apache.hc.core5.http.protocol.HttpContext context)

Deprecated. Use `castOrCreate(HttpContext)`.

#### cast

    public static HttpClientContext cast(org.apache.hc.core5.http.protocol.HttpContext context)

Casts the given generic `HttpContext` as `HttpClientContext`.

Since:
  5.4

#### castOrCreate

    public static HttpClientContext castOrCreate(org.apache.hc.core5.http.protocol.HttpContext context)

Casts the given generic `HttpContext` as `HttpClientContext` or creates new `HttpClientContext` if the given context is null.

Since:
  5.4

#### create

    public static HttpClientContext create()

#### getHttpRoute

    public RouteInfo getHttpRoute()

Represents current route used to execute message exchanges.

This context attribute is expected to be populated by the protocol handler.

#### setRoute

    @Internal
    public void setRoute(HttpRoute route)

Since:
  5.4

#### getRedirectLocations

    public RedirectLocations getRedirectLocations()

Represents a collection of all redirects executed in the context of request execution.

This context attribute is expected to be populated by the protocol handler.

#### setRedirectLocations

    @Internal
    public void setRedirectLocations(RedirectLocations redirectLocations)

Since:
  5.4

#### getCookieStore

    public CookieStore getCookieStore()

Represents a `CookieStore` used in the context of the request execution.

This context attribute can be set by the caller.

#### setCookieStore

    public void setCookieStore(CookieStore cookieStore)

#### getCookieSpec

    public CookieSpec getCookieSpec()

Represents a `CookieSpec` chosen in the context of request execution.

This context attribute is expected to be populated by the protocol handler.

#### setCookieSpec

    @Internal
    public void setCookieSpec(CookieSpec cookieSpec)

Since:
  5.4

#### getCookieOrigin

    public CookieOrigin getCookieOrigin()

Represents a `CookieOrigin` produced in the context of request execution.

This context attribute is expected to be populated by the protocol handler.

#### setCookieOrigin

    @Internal
    public void setCookieOrigin(CookieOrigin cookieOrigin)

Since:
  5.4

#### getCookieSpecRegistry

    public org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> getCookieSpecRegistry()

Represents a `CookieSpecFactory` registry used in the context of the request execution.

This context attribute can be set by the caller.

#### setCookieSpecRegistry

    public void setCookieSpecRegistry(org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> lookup)

#### getAuthSchemeRegistry

    public org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> getAuthSchemeRegistry()

Represents a `AuthSchemeFactory` registry used in the context of the request execution.

This context attribute can be set by the caller.

#### setAuthSchemeRegistry

    public void setAuthSchemeRegistry(org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> lookup)

#### getCredentialsProvider

    public CredentialsProvider getCredentialsProvider()

Represents a `CredentialsProvider` registry used in the context of the request execution.

This context attribute can be set by the caller.

#### setCredentialsProvider

    public void setCredentialsProvider(CredentialsProvider credentialsProvider)

#### getAuthCache

    public AuthCache getAuthCache()

Represents a `AuthCache` used in the context of the request execution.

This context attribute can be set by the caller.

#### setAuthCache

    public void setAuthCache(AuthCache authCache)

#### getAuthExchanges

    public Map<org.apache.hc.core5.http.HttpHost,AuthExchange> getAuthExchanges()

Represents a map of `AuthExchange`s performed in the context of the request execution.

This context attribute is expected to be populated by the protocol handler.

Since:
  5.0

#### getAuthExchange

    public AuthExchange getAuthExchange(org.apache.hc.core5.http.HttpHost host)

Since:
  5.0

#### setAuthExchange

    public void setAuthExchange(org.apache.hc.core5.http.HttpHost host,
                                AuthExchange authExchange)

Since:
  5.0

#### resetAuthExchange

    public void resetAuthExchange(org.apache.hc.core5.http.HttpHost host,
                                  AuthScheme authScheme)

Since:
  5.0

#### getUserToken

    @Deprecated
    public <T> T getUserToken(Class<T> clazz)

Deprecated. Use `getUserToken()`

#### getUserToken

    public Object getUserToken()

Represents an arbitrary user token that identifies the user in the context of the request execution.

This context attribute can be set by the caller.

#### setUserToken

    public void setUserToken(Object userToken)

#### getRequestConfig

    public RequestConfig getRequestConfig()

Represents an `used` in the context of the request execution.

This context attribute can be set by the caller.

#### getRequestConfigOrDefault

    public final RequestConfig getRequestConfigOrDefault()

Returns `RequestConfig` set in the context or `RequestConfig.DEFAULT` if not explicitly set in the context.

Since:
  5.4

#### setRequestConfig

    public void setRequestConfig(RequestConfig requestConfig)

#### getExchangeId

    public String getExchangeId()

Represents an identifier generated for the current message exchange executed in the given context.

This context attribute is expected to be populated by the protocol handler.

Since:
  5.1

#### setExchangeId

    public void setExchangeId(String exchangeId)

Since:
  5.1