/// <summary> /// Converts the request message that was send. /// </summary> /// <param name="request">The request message to be transformed.</param> /// <param name="cancellationToken">The operation cancellation token.</param> /// <returns>The Task representing the asynchronous operation.</returns> private static async Task <HttpRequestMessage> ConvertRequest( Windows.Web.Http.HttpRequestMessage request, CancellationToken cancellationToken) { // Convert the request message var converted = new HttpRequestMessage { Method = new HttpMethod(request.Method.Method), RequestUri = request.RequestUri, Content = await WindowsHttpMessageHandler.ConvertContent(request.Content, cancellationToken) .ConfigureAwait(false) }; // Copy request headers foreach (var header in request.Headers) { converted.Headers.TryAddWithoutValidation(header.Key, header.Value); } // Copy request properties foreach (var prop in request.Properties) { converted.Properties.Add(prop); } // Return the transformed request return(converted); }
/// <summary> /// Converts the received response message. /// </summary> /// <param name="response">The request message to be transformed.</param> /// <param name="cancellationToken">The operation cancellation token.</param> /// <returns>The Task representing the asynchronous operation.</returns> private static async Task <HttpResponseMessage> ConvertResponse( Windows.Web.Http.HttpResponseMessage response, CancellationToken cancellationToken) { // Convert the response var converted = new HttpResponseMessage((HttpStatusCode)(int)response.StatusCode) { ReasonPhrase = response.ReasonPhrase, RequestMessage = await WindowsHttpMessageHandler .ConvertRequest(response.RequestMessage, cancellationToken) .ConfigureAwait(false), Content = await WindowsHttpMessageHandler.ConvertContent(response.Content, cancellationToken) .ConfigureAwait(false), Version = WindowsHttpMessageHandler.GetVersion(response.Version) }; // Copy headers foreach (var header in response.Headers) { converted.Headers.TryAddWithoutValidation(header.Key, header.Value); } // Return the converted message return(converted); }
/// <summary> /// Converts the request message to be send. /// </summary> /// <param name="request">The request message to be transformed.</param> /// <param name="cancellationToken">The operation cancellation token.</param> /// <returns>The Task representing the asynchronous operation.</returns> private static async Task <Windows.Web.Http.HttpRequestMessage> ConvertRequest( HttpRequestMessage request, // ReSharper disable once UnusedParameter.Local CancellationToken cancellationToken) { // Create the request message var converted = new Windows.Web.Http.HttpRequestMessage { Method = new Windows.Web.Http.HttpMethod(request.Method.Method), Content = await WindowsHttpMessageHandler.ConvertContent(request.Content).ConfigureAwait(false), RequestUri = request.RequestUri }; // Copy request headers WindowsHttpMessageHandler.CopyHeaders(request.Headers, converted.Headers); // Copy request properties foreach (var property in request.Properties) { converted.Properties.Add(property); } // Return the transformed request return(converted); }