66
77using System . Diagnostics . CodeAnalysis ;
88using System . Net . Http . Headers ;
9- using System . Text ;
109using System . Text . Json ;
1110using System . Text . Json . Serialization ;
1211
@@ -18,10 +17,6 @@ namespace StandardWebhooks;
1817/// <typeparam name="T">The type of the content.</typeparam>
1918public class WebhookContent < T > : ByteArrayContent
2019{
21- private static readonly Encoding Utf8Encoding = new UTF8Encoding ( false , true ) ;
22- private static readonly JsonSerializerOptions DefaultJsonSerializerOptions =
23- new JsonSerializerOptions ( JsonSerializerDefaults . Web ) { WriteIndented = false } ;
24-
2520 // Maintain copy of the content so we can return it as a string.
2621 private readonly byte [ ] _content ;
2722
@@ -30,7 +25,7 @@ private WebhookContent(byte[] content)
3025 {
3126 _content = content ;
3227
33- Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) { CharSet = Utf8Encoding . WebName } ;
28+ Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) { CharSet = WebhookContentDefaults . Utf8Encoding . WebName } ;
3429 }
3530
3631 /// <summary>Creates a new instance of the <see cref="WebhookContent{T}"/> class.</summary>
@@ -42,7 +37,7 @@ private WebhookContent(byte[] content)
4237 [ RequiresUnreferencedCode ( "This code path does not support NativeAOT. Use the JsonSerializationContext overload for NativeAOT Scenarios." ) ]
4338 public static WebhookContent < T > Create ( T content , JsonSerializerOptions ? jsonOptions = null )
4439 {
45- var utf8bytes = JsonSerializer . SerializeToUtf8Bytes ( content , jsonOptions ?? DefaultJsonSerializerOptions ) ;
40+ var utf8bytes = JsonSerializer . SerializeToUtf8Bytes ( content , jsonOptions ?? WebhookContentDefaults . JsonSerializerOptions ) ;
4641
4742 return new WebhookContent < T > ( utf8bytes ) ;
4843 }
@@ -62,5 +57,5 @@ public static WebhookContent<T> Create(T content, JsonSerializerContext context)
6257 /// Gets the content as a string.
6358 /// </summary>
6459 /// <returns>String representation of the content.</returns>
65- public override string ToString ( ) => Utf8Encoding . GetString ( _content ) ;
66- }
60+ public override string ToString ( ) => WebhookContentDefaults . Utf8Encoding . GetString ( _content ) ;
61+ }
0 commit comments