Class ServiceHttpClient
An implementation of an HTTP client which abstracts the Task of sending HttpRequestMessage.
Inherited Members
Namespace: Unity.Cloud.Common
Assembly: Unity.Cloud.Common.dll
Syntax
public class ServiceHttpClient : IServiceHttpClient, IHttpClient
Constructors
ServiceHttpClient(IHttpClient, IServiceAuthorizer, IAppIdProvider)
Initializes and returns an instance of ServiceHttpClient
Declaration
public ServiceHttpClient(IHttpClient baseHttpClient, IServiceAuthorizer serviceAuthorizer, IAppIdProvider appIdProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IHttpClient | baseHttpClient | The base HTTP client. |
| IServiceAuthorizer | serviceAuthorizer | The authorizer to apply the authorization information to requests. |
| IAppIdProvider | appIdProvider | The App ID provider. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if either |
Fields
ClientTrace
The client trace.
Declaration
public static readonly string ClientTrace
Field Value
| Type | Description |
|---|---|
| string |
Properties
Timeout
The timespan to wait before the request times out.
Declaration
public TimeSpan Timeout { get; set; }
Property Value
| Type | Description |
|---|---|
| TimeSpan |
Methods
SendAsync(HttpRequestMessage, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Sends an asynchronous HTTP request.
Declaration
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, IProgress<HttpProgress> progress, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessage | request | The request to be sent. |
| HttpCompletionOption | completionOption | When the operation should complete. |
| IProgress<HttpProgress> | progress | The progress provider. |
| CancellationToken | cancellationToken | Cancellation token that will try to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> | A task that will hold the HttpResponseMessage once the request is completed |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the request is null. |
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| OperationCanceledException | Thrown when the request is cancelled by a cancellation token or due to timeout. |
SendAsync(HttpRequestMessage, ServiceHttpClientOptions, IProgress<HttpProgress>, CancellationToken)
Declaration
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, ServiceHttpClientOptions options, IProgress<HttpProgress> progress, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessage | request | |
| ServiceHttpClientOptions | options | |
| IProgress<HttpProgress> | progress | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
SendAsync(HttpRequestMessage, ServiceHttpClientOptions, HttpCompletionOption, IProgress<HttpProgress>, CancellationToken)
Send an asynchronous HTTP request.
Declaration
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, ServiceHttpClientOptions options, HttpCompletionOption completionOption, IProgress<HttpProgress> progress, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessage | request | The request to be sent. |
| ServiceHttpClientOptions | options | The options for the client. |
| HttpCompletionOption | completionOption | When the operation should complete. |
| IProgress<HttpProgress> | progress | The progress provider. |
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> | A task that will hold the HttpResponseMessage once the request is completed |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the request is null. |
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| OperationCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |