From d7807842fed7384f4768cf96c78a13f358eacdf1 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Mon, 17 Oct 2022 12:39:38 +0300 Subject: [PATCH] - Changes the ResponeHandler parameter in IRequestAdapter to be a RequestOption --- CHANGELOG.md | 6 ++++ src/HttpClientRequestAdapter.cs | 32 +++++++++++-------- ...rosoft.Kiota.Http.HttpClientLibrary.csproj | 6 ++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d528ec9..0e85251 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +## [1.0.0-preview.11] - 2022-10-17 + +### Changed + +- Changes the ResponeHandler parameter in IRequestAdapter to be a RequestOption + ## [1.0.0-preview.10] - 2022-09-19 ### Added diff --git a/src/HttpClientRequestAdapter.cs b/src/HttpClientRequestAdapter.cs index 8b2eb58..81dfee5 100644 --- a/src/HttpClientRequestAdapter.cs +++ b/src/HttpClientRequestAdapter.cs @@ -78,14 +78,14 @@ private Activity startTracingSpan(RequestInformation requestInfo, string methodN /// /// The instance to send /// The factory of the response model to deserialize the response into. - /// The to use with the response /// The error factories mapping to use in case of a failed request. /// The to use for cancelling the request. - public async Task> SendCollectionAsync(RequestInformation requestInfo, ParsableFactory factory, IResponseHandler responseHandler = default, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) where ModelType : IParsable + public async Task> SendCollectionAsync(RequestInformation requestInfo, ParsableFactory factory, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) where ModelType : IParsable { using var span = startTracingSpan(requestInfo, nameof(SendCollectionAsync)); var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span); requestInfo.Content?.Dispose(); + var responseHandler = GetResponseHandler(requestInfo); if(responseHandler == null) { try { @@ -109,14 +109,14 @@ public async Task> SendCollectionAsync(Request /// Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model collection. /// /// The RequestInformation object to use for the HTTP request. - /// The response handler to use for the HTTP request instead of the default handler. /// The error factories mapping to use in case of a failed request. /// The to use for cancelling the request. /// The deserialized primitive response model collection. - public async Task> SendPrimitiveCollectionAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) { + public async Task> SendPrimitiveCollectionAsync(RequestInformation requestInfo, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) { using var span = startTracingSpan(requestInfo, nameof(SendPrimitiveCollectionAsync)); var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span); requestInfo.Content?.Dispose(); + var responseHandler = GetResponseHandler(requestInfo); if(responseHandler == null) { try { @@ -145,15 +145,15 @@ public async Task> SendPrimitiveCollectionAsync /// The instance to send /// The factory of the response model to deserialize the response into. - /// The to use with the response /// The error factories mapping to use in case of a failed request. /// The to use for cancelling the request. /// The deserialized response model. - public async Task SendAsync(RequestInformation requestInfo, ParsableFactory factory, IResponseHandler responseHandler = null, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) where ModelType : IParsable + public async Task SendAsync(RequestInformation requestInfo, ParsableFactory factory, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) where ModelType : IParsable { using var span = startTracingSpan(requestInfo, nameof(SendAsync)); var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span); requestInfo.Content?.Dispose(); + var responseHandler = GetResponseHandler(requestInfo); if(responseHandler == null) { try { @@ -181,15 +181,15 @@ public async Task SendAsync(RequestInformation requestInfo /// Send a instance with a primitive instance of /// /// The instance to send - /// The to use with the response /// The error factories mapping to use in case of a failed request. /// The to use for cancelling the request. /// The deserialized primitive response model. - public async Task SendPrimitiveAsync(RequestInformation requestInfo, IResponseHandler responseHandler = default, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) + public async Task SendPrimitiveAsync(RequestInformation requestInfo, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) { using var span = startTracingSpan(requestInfo, nameof(SendPrimitiveAsync)); var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span); requestInfo.Content?.Dispose(); + var responseHandler = GetResponseHandler(requestInfo); if(responseHandler == null) { try { @@ -286,15 +286,15 @@ public async Task SendPrimitiveAsync(RequestInformation re /// Send a instance with an empty request body /// /// The instance to send - /// The to use with the response /// The error factories mapping to use in case of a failed request. /// The to use for cancelling the request. /// - public async Task SendNoContentAsync(RequestInformation requestInfo, IResponseHandler responseHandler = null, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) + public async Task SendNoContentAsync(RequestInformation requestInfo, Dictionary> errorMapping = default, CancellationToken cancellationToken = default) { using var span = startTracingSpan(requestInfo, nameof(SendNoContentAsync)); var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span); requestInfo.Content?.Dispose(); + var responseHandler = GetResponseHandler(requestInfo); if(responseHandler == null) { try { @@ -348,10 +348,10 @@ private async Task ThrowFailedResponse(HttpResponseMessage response, Dictionary< !errorMapping.TryGetValue(statusCodeAsString, out errorFactory) && !(statusCodeAsInt >= 400 && statusCodeAsInt < 500 && errorMapping.TryGetValue("4XX", out errorFactory)) && !(statusCodeAsInt >= 500 && statusCodeAsInt < 600 && errorMapping.TryGetValue("5XX", out errorFactory))) - { - activityForAttributes?.SetTag(ErrorMappingFoundAttributeName, false); - throw new ApiException($"The server returned an unexpected status code and no error factory is registered for this code: {statusCodeAsString}"); - } + { + activityForAttributes?.SetTag(ErrorMappingFoundAttributeName, false); + throw new ApiException($"The server returned an unexpected status code and no error factory is registered for this code: {statusCodeAsString}"); + } activityForAttributes?.SetTag(ErrorMappingFoundAttributeName, true); var rootNode = await GetRootParseNode(response); @@ -365,6 +365,10 @@ private async Task ThrowFailedResponse(HttpResponseMessage response, Dictionary< throw ex; } + private static IResponseHandler GetResponseHandler(RequestInformation requestInfo) + { + return requestInfo.GetRequestOption()?.ResponseHandler; + } private async Task GetRootParseNode(HttpResponseMessage response) { using var span = activitySource?.StartActivity(nameof(GetRootParseNode)); diff --git a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj index d8f8157..a0a3a34 100644 --- a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj +++ b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj @@ -14,7 +14,7 @@ true true 1.0.0 - preview.10 + preview.11 true @@ -22,7 +22,7 @@ false 35MSSharedLib1024.snk - - Added tracing support through OpenTelemetry. + - Changes the ResponeHandler parameter in IRequestAdapter to be a RequestOption true LICENSE @@ -31,7 +31,7 @@ - +