Skip to content

Commit

Permalink
Use TryAdd when setting Content-Type
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Oct 4, 2023
1 parent 782c4c5 commit 77f9eb4
Showing 1 changed file with 5 additions and 5 deletions.
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 77f9eb4

Please sign in to comment.