/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ using Amazon.Runtime.Internal.Transform; using Amazon.Runtime.Internal.Util; using System; using System.Collections.Generic; using System.IO; namespace Amazon.Runtime { /// /// The interface for a HTTP request factory. /// /// The type used by the underlying HTTP API to represent the request body. public interface IHttpRequestFactory : IDisposable { /// /// Creates an HTTP request for the given URI. /// /// The request URI. /// An HTTP request. IHttpRequest CreateHttpRequest(Uri requestUri); } /// /// The interface for an HTTP request that is agnostic of the underlying HTTP API. /// /// The type used by the underlying HTTP API to represent the HTTP request content. public interface IHttpRequest : IDisposable { /// /// The HTTP method or verb. /// string Method { get; set; } /// /// The request URI. /// Uri RequestUri { get; } /// /// Configures a request as per the request context. /// /// The request context. void ConfigureRequest(IRequestContext requestContext); /// /// Sets the headers on the request. /// /// A dictionary of header names and values. void SetRequestHeaders(IDictionary headers); /// /// Gets a handle to the request content. /// /// The request content. TRequestContent GetRequestContent(); /// /// Returns the HTTP response. /// /// The HTTP response. IWebResponseData GetResponse(); /// /// Writes a stream to the request body. /// /// The destination where the content stream is written. /// The content stream to be written. /// HTTP content headers. /// The request context. void WriteToRequestBody(TRequestContent requestContent, Stream contentStream, IDictionary contentHeaders, IRequestContext requestContext); /// /// Writes a byte array to the request body. /// /// The destination where the content stream is written. /// The content stream to be written. /// HTTP content headers. void WriteToRequestBody(TRequestContent requestContent, byte[] content, IDictionary contentHeaders); /// /// Sets up the progress listeners /// /// The content stream /// The interval at which progress needs to be published /// The objects which is trigerring the progress changes /// The callback which will be invoked when the progress changed event is trigerred /// an object, incase the progress is setup, else returns the original stream Stream SetupProgressListeners(Stream originalStream, long progressUpdateInterval, object sender, EventHandler callback); /// /// Aborts the HTTP request. /// void Abort(); #if AWS_ASYNC_API /// /// Gets a handle to the request content. /// /// System.Threading.Tasks.Task GetRequestContentAsync(); #if BCL45 System.Threading.Tasks.Task GetRequestContentAsync(System.Threading.CancellationToken cancellationToken); #endif /// /// Returns the HTTP response. /// /// A cancellation token that can be used to cancel the asynchronous operation. /// System.Threading.Tasks.Task GetResponseAsync(System.Threading.CancellationToken cancellationToken); #if BCL45 System.Threading.Tasks.Task WriteToRequestBodyAsync(TRequestContent requestContent, Stream contentStream, IDictionary contentHeaders, IRequestContext requestContext); System.Threading.Tasks.Task WriteToRequestBodyAsync(TRequestContent requestContent, byte[] requestData, IDictionary headers, System.Threading.CancellationToken cancellationToken); #endif #elif AWS_APM_API /// /// Initiates the operation to gets a handle to the request content. /// /// The async callback invoked when the operation completes. /// The state object to be passed to the async callback. /// IAsyncResult that represents an async operation. IAsyncResult BeginGetRequestContent(AsyncCallback callback, object state); /// /// Ends the operation to gets a handle to the request content. /// /// IAsyncResult that represents an async operation. /// The request content. TRequestContent EndGetRequestContent(IAsyncResult asyncResult); /// /// Initiates the operation to Returns the HTTP response. /// /// The async callback invoked when the operation completes. /// The state object to be passed to the async callback. /// IAsyncResult that represents an async operation. IAsyncResult BeginGetResponse(AsyncCallback callback, object state); /// /// Ends the operation to Returns the HTTP response. /// /// IAsyncResult that represents an async operation. /// The HTTP response. IWebResponseData EndGetResponse(IAsyncResult asyncResult); #endif } }