|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 | 4 | /**
|
5 |
| - * Package containing OkHttp HTTP client plugin for azure-core. |
| 5 | + * <p><a href="https://learn.microsoft.com/en-us/java/api/overview/azure/core-http-okhttp-readme?view=azure-java-stable"> |
| 6 | + * Azure Core Http OkHttp</a> client library is a plugin for the azure-core HTTP client API. It allows you to use OkHttp |
| 7 | + * as the underlying HTTP client for communicating with Azure services. OkHttp is a popular and efficient HTTP client |
| 8 | + * that supports features such as HTTP/2, connection pooling, compression, and caching. To use the OkHttp client library, |
| 9 | + * you need to include the dependency in your project and configure it when creating a service client. |
| 10 | + * For more details refer to our <a href="https://learn.microsoft.com/azure/developer/java/sdk/http-client-pipeline#http-clients">conceptual documentation</a>.</p> |
| 11 | + * |
| 12 | + * <p><strong>Sample: Construct OkHttpAsyncHttpClient with Default Configuration</strong></p> |
| 13 | + * |
| 14 | + * <p>The following code sample demonstrates the creation of a OkHttp HttpClient that uses port 80 and has no proxy.</p> |
| 15 | + * |
| 16 | + * <!-- src_embed readme-sample-createBasicClient --> |
| 17 | + * <pre> |
| 18 | + * HttpClient client = new OkHttpAsyncHttpClientBuilder().build(); |
| 19 | + * </pre> |
| 20 | + * <!-- end readme-sample-createBasicClient --> |
| 21 | + * |
| 22 | + * <hr> |
| 23 | + * |
| 24 | + * <h2><strong>Using OkHttpAsyncHttpClient with Http Proxy</strong></h2> |
| 25 | + * |
| 26 | + * <p>Configuring the OkHttp client with a proxy in the context of Azure Java SDK is relevant when your application needs |
| 27 | + * to communicate with Azure services through a proxy server. For more details refer to our |
| 28 | + * <a href="https://learn.microsoft.com/azure/developer/java/sdk/proxying#http-proxy-configuration">conceptual documentation</a>.</p> |
| 29 | + * |
| 30 | + * <p>The following code sample demonstrates the creation of a OkHttp HttpClient that is using a proxy.</p> |
| 31 | + * |
| 32 | + * <!-- src_embed com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder.proxy#ProxyOptions --> |
| 33 | + * <pre> |
| 34 | + * final String proxyHost = "<proxy-host>"; // e.g. localhost |
| 35 | + * final int proxyPort = 9999; // Proxy port |
| 36 | + * ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, |
| 37 | + * new InetSocketAddress(proxyHost, proxyPort)); |
| 38 | + * HttpClient client = new OkHttpAsyncHttpClientBuilder() |
| 39 | + * .proxy(proxyOptions) |
| 40 | + * .build(); |
| 41 | + * </pre> |
| 42 | + * <!-- end com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder.proxy#ProxyOptions --> |
| 43 | + * |
| 44 | + * <hr> |
| 45 | + * |
| 46 | + * <h2><strong>Using OkHttpAsyncHttpClient with HTTP/2 Support</strong></h2> |
| 47 | + * |
| 48 | + * <p>The following code sample demonstrates the creation of a OkHttp HttpClient that supports both the HTTP/1.1 and |
| 49 | + * HTTP/2 protocols, with HTTP/2 being the preferred protocol.</p> |
| 50 | + * |
| 51 | + * <!-- src_embed readme-sample-useHttp2WithConfiguredOkHttpClient --> |
| 52 | + * <pre> |
| 53 | + * // Constructs an HttpClient that supports both HTTP/1.1 and HTTP/2 with HTTP/2 being the preferred protocol. |
| 54 | + * // This is the default handling for OkHttp. |
| 55 | + * HttpClient client = new OkHttpAsyncHttpClientBuilder(new OkHttpClient.Builder() |
| 56 | + * .protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1)) |
| 57 | + * .build()) |
| 58 | + * .build(); |
| 59 | + * </pre> |
| 60 | + * <!-- end readme-sample-useHttp2WithConfiguredOkHttpClient --> |
| 61 | + * |
| 62 | + * <p>It is also possible to create a OkHttp HttpClient that only supports HTTP/2.</p> |
| 63 | + * |
| 64 | + * <!-- src_embed readme-sample-useHttp2OnlyWithConfiguredOkHttpClient --> |
| 65 | + * <pre> |
| 66 | + * // Constructs an HttpClient that only supports HTTP/2. |
| 67 | + * HttpClient client = new OkHttpAsyncHttpClientBuilder(new OkHttpClient.Builder() |
| 68 | + * .protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE)) |
| 69 | + * .build()) |
| 70 | + * .build(); |
| 71 | + * </pre> |
| 72 | + * <!-- end readme-sample-useHttp2OnlyWithConfiguredOkHttpClient --> |
| 73 | + * |
| 74 | + * @see com.azure.core.http.okhttp.OkHttpAsyncHttpClient |
| 75 | + * @see com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder |
| 76 | + * @see okhttp3.OkHttpClient |
6 | 77 | */
|
7 | 78 | package com.azure.core.http.okhttp;
|
0 commit comments