Skip to content

Commit

Permalink
Merge pull request #132 from andreaTP/use-tryadd
Browse files Browse the repository at this point in the history
Use TryAdd when setting Content-Type
  • Loading branch information
baywet authored Oct 5, 2023
2 parents 782c4c5 + 9abd775 commit ea0782a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.3.4</VersionPrefix>
<VersionPrefix>1.3.5</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
Expand Down
10 changes: 5 additions & 5 deletions src/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!);
/// <summary>
Expand All @@ -211,7 +211,7 @@ public void SetContentFromParsable<T>(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();
}
/// <summary>
Expand All @@ -232,7 +232,7 @@ public void SetContentFromParsable<T>(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)
Expand Down Expand Up @@ -261,7 +261,7 @@ public void SetContentFromScalarCollection<T>(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();
}
/// <summary>
Expand Down Expand Up @@ -323,7 +323,7 @@ public void SetContentFromScalar<T>(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();
}
}
Expand Down

0 comments on commit ea0782a

Please sign in to comment.