3
3
4
4
#nullable disable
5
5
6
+ using System . Text . Json ;
7
+
6
8
namespace Microsoft . AspNetCore . StaticWebAssets . Tasks ;
7
9
8
10
internal static class WellKnownResponseHeaders
@@ -17,6 +19,16 @@ internal static class WellKnownResponseHeaders
17
19
public const string LastModified = "Last-Modified" ;
18
20
public const string Vary = "Vary" ;
19
21
22
+ // Pre-encoded property names for high-performance JSON serialization
23
+ public static readonly JsonEncodedText AcceptRangesPropertyName = JsonEncodedText . Encode ( AcceptRanges ) ;
24
+ public static readonly JsonEncodedText CacheControlPropertyName = JsonEncodedText . Encode ( CacheControl ) ;
25
+ public static readonly JsonEncodedText ContentEncodingPropertyName = JsonEncodedText . Encode ( ContentEncoding ) ;
26
+ public static readonly JsonEncodedText ContentLengthPropertyName = JsonEncodedText . Encode ( ContentLength ) ;
27
+ public static readonly JsonEncodedText ContentTypePropertyName = JsonEncodedText . Encode ( ContentType ) ;
28
+ public static readonly JsonEncodedText ETagPropertyName = JsonEncodedText . Encode ( ETag ) ;
29
+ public static readonly JsonEncodedText LastModifiedPropertyName = JsonEncodedText . Encode ( LastModified ) ;
30
+ public static readonly JsonEncodedText VaryPropertyName = JsonEncodedText . Encode ( Vary ) ;
31
+
20
32
public static string TryGetInternedHeaderName ( ReadOnlySpan < byte > headerNameSpan )
21
33
{
22
34
return headerNameSpan . Length switch
@@ -40,4 +52,26 @@ public static string TryGetInternedHeaderName(ReadOnlySpan<byte> headerNameSpan)
40
52
_ => null
41
53
} ;
42
54
}
55
+
56
+ public static JsonEncodedText ? TryGetPreEncodedHeaderName ( string name ) =>
57
+ name ? . Length switch
58
+ {
59
+ 4 => name [ 0 ] switch
60
+ {
61
+ 'E' when string . Equals ( name , ETag , StringComparison . Ordinal ) => ETagPropertyName ,
62
+ 'V' when string . Equals ( name , Vary , StringComparison . Ordinal ) => VaryPropertyName ,
63
+ _ => null
64
+ } ,
65
+ 12 when string . Equals ( name , ContentType , StringComparison . Ordinal ) => ContentTypePropertyName ,
66
+ 13 => name [ 0 ] switch
67
+ {
68
+ 'A' when string . Equals ( name , AcceptRanges , StringComparison . Ordinal ) => AcceptRangesPropertyName ,
69
+ 'C' when string . Equals ( name , CacheControl , StringComparison . Ordinal ) => CacheControlPropertyName ,
70
+ 'L' when string . Equals ( name , LastModified , StringComparison . Ordinal ) => LastModifiedPropertyName ,
71
+ _ => null
72
+ } ,
73
+ 14 when string . Equals ( name , ContentLength , StringComparison . Ordinal ) => ContentLengthPropertyName ,
74
+ 16 when string . Equals ( name , ContentEncoding , StringComparison . Ordinal ) => ContentEncodingPropertyName ,
75
+ _ => null
76
+ } ;
43
77
}
0 commit comments