From 77f9eb4ee50455719dcc0d36e5e3c7f13ba2e751 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Wed, 4 Oct 2023 10:59:25 +0100 Subject: [PATCH 1/2] Use TryAdd when setting Content-Type --- src/RequestInformation.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RequestInformation.cs b/src/RequestInformation.cs index b9485a91..70b4ab18 100644 --- a/src/RequestInformation.cs +++ b/src/RequestInformation.cs @@ -195,7 +195,7 @@ public void SetStreamContent(Stream content) using var activity = _activitySource?.StartActivity(nameof(SetStreamContent)); SetRequestType(content, activity); Content = content; - Headers.Add(ContentTypeHeader, BinaryContentType); + Headers.TryAdd(ContentTypeHeader, BinaryContentType); } private static ActivitySource _activitySource = new(typeof(RequestInformation).Namespace!); /// @@ -211,7 +211,7 @@ public void SetContentFromParsable(IRequestAdapter requestAdapter, string con using var writer = GetSerializationWriter(requestAdapter, contentType, items); SetRequestType(items.FirstOrDefault(static x => x != null), activity); writer.WriteCollectionOfObjectValues(null, items); - Headers.Add(ContentTypeHeader, contentType); + Headers.TryAdd(ContentTypeHeader, contentType); Content = writer.GetSerializedContent(); } /// @@ -232,7 +232,7 @@ public void SetContentFromParsable(IRequestAdapter requestAdapter, string con mpBody.RequestAdapter = requestAdapter; } writer.WriteObjectValue(null, item); - Headers.Add(ContentTypeHeader, contentType); + Headers.TryAdd(ContentTypeHeader, contentType); Content = writer.GetSerializedContent(); } private static void SetRequestType(object? result, Activity? activity) @@ -261,7 +261,7 @@ public void SetContentFromScalarCollection(IRequestAdapter requestAdapter, st using var writer = GetSerializationWriter(requestAdapter, contentType, items); SetRequestType(items.FirstOrDefault(static x => x != null), activity); writer.WriteCollectionOfPrimitiveValues(null, items); - Headers.Add(ContentTypeHeader, contentType); + Headers.TryAdd(ContentTypeHeader, contentType); Content = writer.GetSerializedContent(); } /// @@ -323,7 +323,7 @@ public void SetContentFromScalar(IRequestAdapter requestAdapter, string conte default: throw new InvalidOperationException($"error serialization data value with unknown type {item?.GetType()}"); } - Headers.Add(ContentTypeHeader, contentType); + Headers.TryAdd(ContentTypeHeader, contentType); Content = writer.GetSerializedContent(); } } From 9abd775f48e990aee7570d0f887dffb8accc9e89 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 5 Oct 2023 10:24:57 -0400 Subject: [PATCH 2/2] - adds changelog entry for try add fix --- CHANGELOG.md | 6 ++++++ src/Microsoft.Kiota.Abstractions.csproj | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f7e284..c3de839c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.3.5] - 2023-10-05 + +### Changed + +- Uses headers try add when setting the content type. + ## [1.3.4] - 2023-10-04 ### Changed diff --git a/src/Microsoft.Kiota.Abstractions.csproj b/src/Microsoft.Kiota.Abstractions.csproj index 0cd3dfca..31466815 100644 --- a/src/Microsoft.Kiota.Abstractions.csproj +++ b/src/Microsoft.Kiota.Abstractions.csproj @@ -14,7 +14,7 @@ https://aka.ms/kiota/docs true true - 1.3.4 + 1.3.5 true false