Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TryAdd when setting Content-Type #132

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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