net.snowflake.client.core

## Class HttpUtil

- java.lang.Object
- - net.snowflake.client.core.HttpUtil

    public class HttpUtil
    extends Object

### Nested Class Summary

Nested Classes
`static class` `HttpUtil.HttpInputStream`

### Field Summary

Fields
`static Map<HttpClientSettingsKey,org.apache.http.impl.client.CloseableHttpClient>` `httpClient` The unique httpClient shared by all connections.
`static String` `JDBC_MAX_CONNECTIONS_PER_ROUTE_PROPERTY`
`static String` `JDBC_MAX_CONNECTIONS_PROPERTY`
`static String` `JDBC_TTL`

### Constructor Summary

Constructors
Constructor and Description
`HttpUtil()`

### Method Summary

All Methods Static Methods Concrete Methods
`static org.apache.http.impl.client.CloseableHttpClient` `buildHttpClient(HttpClientSettingsKey key, File ocspCacheFile, boolean downloadCompressed)` Build an Http client using our set of default.
`static void` `closeExpiredAndIdleConnections()`
`static String` `executeGeneralRequest(org.apache.http.client.methods.HttpRequestBase httpRequest, int retryTimeout, org.apache.http.impl.client.CloseableHttpClient httpClient)` Executes a HTTP request for Snowflake
`static String` `executeGeneralRequest(org.apache.http.client.methods.HttpRequestBase httpRequest, int retryTimeout, HttpClientSettingsKey ocspAndProxyKey)` Executes a HTTP request for Snowflake.
`static String` `executeRequest(org.apache.http.client.methods.HttpRequestBase httpRequest, int retryTimeout, int injectSocketTimeout, AtomicBoolean canceling, boolean includeRetryParameters, boolean retryOnHTTP403, HttpClientSettingsKey ocspAndProxyKey)` Executes a HTTP request for Snowflake.
`static org.apache.http.client.config.RequestConfig` `getDefaultRequestConfigWithSocketTimeout(int soTimeoutMs, boolean withoutCookies)` Return a request configuration inheriting from the default request configuration of the shared HttpClient with a different socket timeout.
`static long` `getDownloadedConditionTimeoutInSeconds()`
`static org.apache.http.impl.client.CloseableHttpClient` `getHttpClient(HttpClientSettingsKey ocspAndProxyKey)` Gets HttpClient with insecureMode false
`static org.apache.http.impl.client.CloseableHttpClient` `getHttpClientWithoutDecompression(HttpClientSettingsKey ocspAndProxyKey)` Gets HttpClient with insecureMode false and disabling decompression
`static org.apache.http.client.config.RequestConfig` `getRequestConfigWithoutCookies()` Return a request configuration inheriting from the default request configuration of the shared HttpClient with the coopkie spec set to ignore.
`static org.apache.http.impl.client.CloseableHttpClient` `initHttpClient(HttpClientSettingsKey key, File ocspCacheFile)` Accessor for the HTTP client singleton.
`static org.apache.http.impl.client.CloseableHttpClient` `initHttpClientWithoutDecompression(HttpClientSettingsKey key, File ocspCacheFile)` Accessor for the HTTP client singleton.
`static boolean` `isSocksProxyDisabled()` Returns whether the SOCKS proxy is disabled for this JVM
`static void` `setProxyForAzure(HttpClientSettingsKey key, com.microsoft.azure.storage.OperationContext opContext)` A static function to set Azure proxy params when there is a valid session
`static void` `setProxyForS3(HttpClientSettingsKey key, com.amazonaws.ClientConfiguration clientConfig)` A static function to set S3 proxy params when there is a valid session
`static void` `setRequestConfig(org.apache.http.client.config.RequestConfig requestConfig)`
`static void` `setSessionlessProxyForAzure(Properties proxyProperties, com.microsoft.azure.storage.OperationContext opContext)` A static function to set Azure proxy params for sessionless connections using the proxy params from the StageInfo
`static void` `setSessionlessProxyForS3(Properties proxyProperties, com.amazonaws.ClientConfiguration clientConfig)` A static function to set S3 proxy params for sessionless connections using the proxy params from the StageInfo
`static void` `setSocksProxyDisabled(boolean socksProxyDisabled)` Enables/disables use of the SOCKS proxy when creating sockets
`static void` `updateRoutePlanner(HttpClientSettingsKey key)`

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

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

### Field Detail

#### JDBC_TTL

    public static final String JDBC_TTL

See Also:
  Constant Field Values

#### JDBC_MAX_CONNECTIONS_PROPERTY

    public static final String JDBC_MAX_CONNECTIONS_PROPERTY

See Also:
  Constant Field Values

#### JDBC_MAX_CONNECTIONS_PER_ROUTE_PROPERTY

    public static final String JDBC_MAX_CONNECTIONS_PER_ROUTE_PROPERTY

See Also:
  Constant Field Values

#### httpClient

    public static Map<HttpClientSettingsKey,org.apache.http.impl.client.CloseableHttpClient> httpClient

The unique httpClient shared by all connections. This will benefit long- lived clients. Key = proxy host + proxy port + nonProxyHosts, Value = Map of [OCSPMode, HttpClient]

### Constructor Detail

#### HttpUtil

    public HttpUtil()

### Method Detail

#### getDownloadedConditionTimeoutInSeconds

    public static long getDownloadedConditionTimeoutInSeconds()

#### closeExpiredAndIdleConnections

    public static void closeExpiredAndIdleConnections()

#### setProxyForS3

    public static void setProxyForS3(HttpClientSettingsKey key,
                                     com.amazonaws.ClientConfiguration clientConfig)

A static function to set S3 proxy params when there is a valid session

Parameters:
  `key` - key to HttpClient map containing OCSP and proxy info
  `clientConfig` - the configuration needed by S3 to set the proxy

#### setSessionlessProxyForS3

    public static void setSessionlessProxyForS3(Properties proxyProperties,
                                                com.amazonaws.ClientConfiguration clientConfig)
                                         throws SnowflakeSQLException

A static function to set S3 proxy params for sessionless connections using the proxy params from the StageInfo

Parameters:
  `proxyProperties` - proxy properties
  `clientConfig` - the configuration needed by S3 to set the proxy
Throws:
  `SnowflakeSQLException`

#### setSessionlessProxyForAzure

    public static void setSessionlessProxyForAzure(Properties proxyProperties,
                                                   com.microsoft.azure.storage.OperationContext opContext)
                                            throws SnowflakeSQLException

A static function to set Azure proxy params for sessionless connections using the proxy params from the StageInfo

Parameters:
  `proxyProperties` - proxy properties
  `opContext` - the configuration needed by Azure to set the proxy
Throws:
  `SnowflakeSQLException`

#### setProxyForAzure

    public static void setProxyForAzure(HttpClientSettingsKey key,
                                        com.microsoft.azure.storage.OperationContext opContext)

A static function to set Azure proxy params when there is a valid session

Parameters:
  `key` - key to HttpClient map containing OCSP and proxy info
  `opContext` - the configuration needed by Azure to set the proxy

#### buildHttpClient

    public static org.apache.http.impl.client.CloseableHttpClient buildHttpClient(@Nullable
                                                                                  HttpClientSettingsKey key,
                                                                                  File ocspCacheFile,
                                                                                  boolean downloadCompressed)

Build an Http client using our set of default.

Parameters:
  `key` - Key to HttpClient hashmap containing OCSP mode and proxy information, could be null
  `ocspCacheFile` - OCSP response cache file. If null, the default OCSP response file will be used.
  `downloadCompressed` - Whether the HTTP client should be built requesting no decompression
Returns:
  HttpClient object

#### updateRoutePlanner

    public static void updateRoutePlanner(HttpClientSettingsKey key)

#### getHttpClient

    public static org.apache.http.impl.client.CloseableHttpClient getHttpClient(HttpClientSettingsKey ocspAndProxyKey)

Gets HttpClient with insecureMode false

Parameters:
  `ocspAndProxyKey` - OCSP mode and proxy settings for httpclient
Returns:
  HttpClient object shared across all connections

#### getHttpClientWithoutDecompression

    public static org.apache.http.impl.client.CloseableHttpClient getHttpClientWithoutDecompression(HttpClientSettingsKey ocspAndProxyKey)

Gets HttpClient with insecureMode false and disabling decompression

Parameters:
  `ocspAndProxyKey` - OCSP mode and proxy settings for httpclient
Returns:
  HttpClient object shared across all connections

#### initHttpClientWithoutDecompression

    public static org.apache.http.impl.client.CloseableHttpClient initHttpClientWithoutDecompression(HttpClientSettingsKey key,
                                                                                                     File ocspCacheFile)

Accessor for the HTTP client singleton.

Parameters:
  `key` - contains information needed to build specific HttpClient
  `ocspCacheFile` - OCSP response cache file name. if null, the default file will be used.
Returns:
  HttpClient object shared across all connections

#### initHttpClient

    public static org.apache.http.impl.client.CloseableHttpClient initHttpClient(HttpClientSettingsKey key,
                                                                                 File ocspCacheFile)

Accessor for the HTTP client singleton.

Parameters:
  `key` - contains information needed to build specific HttpClient
  `ocspCacheFile` - OCSP response cache file name. if null, the default file will be used.
Returns:
  HttpClient object shared across all connections

#### getDefaultRequestConfigWithSocketTimeout

    public static org.apache.http.client.config.RequestConfig getDefaultRequestConfigWithSocketTimeout(int soTimeoutMs,
                                                                                                       boolean withoutCookies)

Return a request configuration inheriting from the default request configuration of the shared HttpClient with a different socket timeout.

Parameters:
  `soTimeoutMs` - - custom socket timeout in milli-seconds
  `withoutCookies` - - whether this request should ignore cookies or not
Returns:
  RequestConfig object

#### getRequestConfigWithoutCookies

    public static org.apache.http.client.config.RequestConfig getRequestConfigWithoutCookies()

Return a request configuration inheriting from the default request configuration of the shared HttpClient with the coopkie spec set to ignore.

Returns:
  RequestConfig object

#### setRequestConfig

    public static void setRequestConfig(org.apache.http.client.config.RequestConfig requestConfig)

#### setSocksProxyDisabled

    public static void setSocksProxyDisabled(boolean socksProxyDisabled)

Enables/disables use of the SOCKS proxy when creating sockets

Parameters:
  `socksProxyDisabled` - new value

#### isSocksProxyDisabled

    public static boolean isSocksProxyDisabled()

Returns whether the SOCKS proxy is disabled for this JVM

Returns:
  whether the SOCKS proxy is disabled

#### executeGeneralRequest

    public static String executeGeneralRequest(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                               int retryTimeout,
                                               HttpClientSettingsKey ocspAndProxyKey)
                                        throws SnowflakeSQLException,
                                               IOException

Executes a HTTP request for Snowflake.

Parameters:
  `httpRequest` - HttpRequestBase
  `retryTimeout` - retry timeout
  `ocspAndProxyKey` - OCSP mode and proxy settings for httpclient
Returns:
  response
Throws:
  `SnowflakeSQLException` - if Snowflake error occurs
  `IOException` - raises if a general IO error occurs

#### executeGeneralRequest

    public static String executeGeneralRequest(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                               int retryTimeout,
                                               org.apache.http.impl.client.CloseableHttpClient httpClient)
                                        throws SnowflakeSQLException,
                                               IOException

Executes a HTTP request for Snowflake

Parameters:
  `httpRequest` - HttpRequestBase
  `retryTimeout` - retry timeout
  `httpClient` - client object used to communicate with other machine
Returns:
  response
Throws:
  `SnowflakeSQLException` - if Snowflake error occurs
  `IOException` - raises if a general IO error occurs

#### executeRequest

    public static String executeRequest(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                        int retryTimeout,
                                        int injectSocketTimeout,
                                        AtomicBoolean canceling,
                                        boolean includeRetryParameters,
                                        boolean retryOnHTTP403,
                                        HttpClientSettingsKey ocspAndProxyKey)
                                 throws SnowflakeSQLException,
                                        IOException

Executes a HTTP request for Snowflake.

Parameters:
  `httpRequest` - HttpRequestBase
  `retryTimeout` - retry timeout
  `injectSocketTimeout` - injecting socket timeout
  `canceling` - canceling?
  `includeRetryParameters` - whether to include retry parameters in retried requests
  `retryOnHTTP403` - whether to retry on HTTP 403 or not
  `ocspAndProxyKey` - OCSP mode and proxy settings for httpclient
Returns:
  response
Throws:
  `SnowflakeSQLException` - if Snowflake error occurs
  `IOException` - raises if a general IO error occurs