1
1
using System ;
2
+ using System . Collections . Frozen ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
5
+ using System . Runtime . CompilerServices ;
4
6
using System . Text ;
5
7
using System . Threading . Tasks ;
6
8
7
9
namespace NZ . Orz . Http ;
8
10
9
11
public static class HeaderNames
10
12
{
11
- private const string PseudoHeaderNamesObsoletionMessage = "This is obsolete and will be removed in a future version. Header dictionaries do not contain this key." ;
12
-
13
- // Use readonly statics rather than constants so ReferenceEquals works
14
-
15
13
/// <summary>Gets the <c>Accept</c> HTTP header name.</summary>
16
14
public static readonly string Accept = "Accept" ;
17
15
@@ -60,10 +58,6 @@ public static class HeaderNames
60
58
/// <summary>Gets the <c>Alt-Svc</c> HTTP header name.</summary>
61
59
public static readonly string AltSvc = "Alt-Svc" ;
62
60
63
- /// <summary>Gets the <c>:authority</c> HTTP header name.</summary>
64
- [ Obsolete ( PseudoHeaderNamesObsoletionMessage , false ) ]
65
- public static readonly string Authority = ":authority" ;
66
-
67
61
/// <summary>Gets the <c>Authorization</c> HTTP header name.</summary>
68
62
public static readonly string Authorization = "Authorization" ;
69
63
@@ -178,17 +172,9 @@ public static class HeaderNames
178
172
/// <summary>Gets the <c>Max-Forwards</c> HTTP header name.</summary>
179
173
public static readonly string MaxForwards = "Max-Forwards" ;
180
174
181
- /// <summary>Gets the <c>:method</c> HTTP header name.</summary>
182
- [ Obsolete ( PseudoHeaderNamesObsoletionMessage , false ) ]
183
- public static readonly string Method = ":method" ;
184
-
185
175
/// <summary>Gets the <c>Origin</c> HTTP header name.</summary>
186
176
public static readonly string Origin = "Origin" ;
187
177
188
- /// <summary>Gets the <c>:path</c> HTTP header name.</summary>
189
- [ Obsolete ( PseudoHeaderNamesObsoletionMessage , false ) ]
190
- public static readonly string Path = ":path" ;
191
-
192
178
/// <summary>Gets the <c>Pragma</c> HTTP header name.</summary>
193
179
public static readonly string Pragma = "Pragma" ;
194
180
@@ -213,10 +199,6 @@ public static class HeaderNames
213
199
/// <summary>Gets the <c>Request-Id</c> HTTP header name.</summary>
214
200
public static readonly string RequestId = "Request-Id" ;
215
201
216
- /// <summary>Gets the <c>:scheme</c> HTTP header name.</summary>
217
- [ Obsolete ( PseudoHeaderNamesObsoletionMessage , false ) ]
218
- public static readonly string Scheme = ":scheme" ;
219
-
220
202
/// <summary>Gets the <c>Sec-WebSocket-Accept</c> HTTP header name.</summary>
221
203
public static readonly string SecWebSocketAccept = "Sec-WebSocket-Accept" ;
222
204
@@ -238,10 +220,6 @@ public static class HeaderNames
238
220
/// <summary>Gets the <c>Set-Cookie</c> HTTP header name.</summary>
239
221
public static readonly string SetCookie = "Set-Cookie" ;
240
222
241
- /// <summary>Gets the <c>:status</c> HTTP header name.</summary>
242
- [ Obsolete ( PseudoHeaderNamesObsoletionMessage , false ) ]
243
- public static readonly string Status = ":status" ;
244
-
245
223
/// <summary>Gets the <c>Strict-Transport-Security</c> HTTP header name.</summary>
246
224
public static readonly string StrictTransportSecurity = "Strict-Transport-Security" ;
247
225
@@ -281,9 +259,6 @@ public static class HeaderNames
281
259
/// <summary>Gets the <c>Warning</c> HTTP header name.</summary>
282
260
public static readonly string Warning = "Warning" ;
283
261
284
- /// <summary>Gets the <c>Sec-WebSocket-Protocol</c> HTTP header name.</summary>
285
- public static readonly string WebSocketSubProtocols = "Sec-WebSocket-Protocol" ;
286
-
287
262
/// <summary>Gets the <c>WWW-Authenticate</c> HTTP header name.</summary>
288
263
public static readonly string WWWAuthenticate = "WWW-Authenticate" ;
289
264
@@ -305,7 +280,7 @@ public static class HeaderNames
305
280
/// <summary>Gets the <c>X-XSS-Protection</c> HTTP header name.</summary>
306
281
public static readonly string XXSSProtection = "X-XSS-Protection" ;
307
282
308
- private static readonly HashSet < string > _internedHeaderNames = new HashSet < string > ( 91 , StringComparer . OrdinalIgnoreCase )
283
+ private static readonly FrozenSet < string > _internedHeaderNames = new HashSet < string > ( StringComparer . OrdinalIgnoreCase )
309
284
{
310
285
HeaderNames . Accept ,
311
286
HeaderNames . AcceptCharset ,
@@ -390,16 +365,16 @@ public static class HeaderNames
390
365
HeaderNames . Vary ,
391
366
HeaderNames . Via ,
392
367
HeaderNames . Warning ,
393
- HeaderNames . WebSocketSubProtocols ,
394
368
HeaderNames . WWWAuthenticate ,
395
369
HeaderNames . XContentTypeOptions ,
396
370
HeaderNames . XFrameOptions ,
397
371
HeaderNames . XPoweredBy ,
398
372
HeaderNames . XRequestedWith ,
399
373
HeaderNames . XUACompatible ,
400
374
HeaderNames . XXSSProtection ,
401
- } ;
375
+ } . ToFrozenSet ( StringComparer . OrdinalIgnoreCase ) ;
402
376
377
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
403
378
public static string GetInternedHeaderName ( string name )
404
379
{
405
380
// Some headers can be very long lived; for example those on a WebSocket connection
@@ -411,4 +386,210 @@ public static string GetInternedHeaderName(string name)
411
386
412
387
return name ;
413
388
}
389
+
390
+ private static readonly FrozenDictionary < string , KnownHeaderType > _internedHeaderType = new Dictionary < string , KnownHeaderType > ( StringComparer . OrdinalIgnoreCase )
391
+ {
392
+ { HeaderNames . Host , KnownHeaderType . Host } ,
393
+ //{ HeaderNames.Accept, KnownHeaderType.Accept },
394
+ //{ HeaderNames.AcceptCharset, KnownHeaderType.AcceptCharset },
395
+ //{ HeaderNames.AcceptEncoding, KnownHeaderType.AcceptEncoding },
396
+ //{ HeaderNames.AcceptLanguage, KnownHeaderType.AcceptLanguage },
397
+ //{ HeaderNames.AcceptRanges, KnownHeaderType.AcceptRanges },
398
+ //{ HeaderNames.AccessControlAllowCredentials, KnownHeaderType.AccessControlAllowCredentials },
399
+ //{ HeaderNames.AccessControlAllowHeaders, KnownHeaderType.AccessControlAllowHeaders },
400
+ //{ HeaderNames.AccessControlAllowMethods, KnownHeaderType.AccessControlAllowMethods },
401
+ //{ HeaderNames.AccessControlAllowOrigin, KnownHeaderType.AccessControlAllowOrigin },
402
+ //{ HeaderNames.AccessControlExposeHeaders, KnownHeaderType.AccessControlExposeHeaders },
403
+ //{ HeaderNames.AccessControlMaxAge, KnownHeaderType.AccessControlMaxAge },
404
+ //{ HeaderNames.AccessControlRequestHeaders, KnownHeaderType.AccessControlRequestHeaders },
405
+ //{ HeaderNames.AccessControlRequestMethod, KnownHeaderType.AccessControlRequestMethod },
406
+ //{ HeaderNames.Age, KnownHeaderType.Age },
407
+ //{ HeaderNames.Allow, KnownHeaderType.Allow },
408
+ //{ HeaderNames.AltSvc, KnownHeaderType.AltSvc },
409
+ //{ HeaderNames.Authorization, KnownHeaderType.Authorization },
410
+ //{ HeaderNames.Baggage, KnownHeaderType.Baggage },
411
+ //{ HeaderNames.CacheControl, KnownHeaderType.CacheControl },
412
+ //{ HeaderNames.Connection, KnownHeaderType.Connection },
413
+ //{ HeaderNames.ContentDisposition, KnownHeaderType.ContentDisposition },
414
+ //{ HeaderNames.ContentEncoding, KnownHeaderType.ContentEncoding },
415
+ //{ HeaderNames.ContentLanguage, KnownHeaderType.ContentLanguage },
416
+ //{ HeaderNames.ContentLength, KnownHeaderType.ContentLength },
417
+ //{ HeaderNames.ContentLocation, KnownHeaderType.ContentLocation },
418
+ //{ HeaderNames.ContentMD5, KnownHeaderType.ContentMD5 },
419
+ //{ HeaderNames.ContentRange, KnownHeaderType.ContentRange },
420
+ //{ HeaderNames.ContentSecurityPolicy, KnownHeaderType.ContentSecurityPolicy },
421
+ //{ HeaderNames.ContentSecurityPolicyReportOnly, KnownHeaderType.ContentSecurityPolicyReportOnly },
422
+ //{ HeaderNames.ContentType, KnownHeaderType.ContentType },
423
+ //{ HeaderNames.CorrelationContext, KnownHeaderType.CorrelationContext },
424
+ //{ HeaderNames.Cookie, KnownHeaderType.Cookie },
425
+ //{ HeaderNames.Date, KnownHeaderType.Date },
426
+ //{ HeaderNames.DNT, KnownHeaderType.DNT },
427
+ //{ HeaderNames.ETag, KnownHeaderType.ETag },
428
+ //{ HeaderNames.Expires, KnownHeaderType.Expires },
429
+ //{ HeaderNames.Expect, KnownHeaderType.Expect },
430
+ //{ HeaderNames.From, KnownHeaderType.From },
431
+ //{ HeaderNames.GrpcAcceptEncoding, KnownHeaderType.GrpcAcceptEncoding },
432
+ //{ HeaderNames.GrpcEncoding, KnownHeaderType.GrpcEncoding },
433
+ //{ HeaderNames.GrpcMessage, KnownHeaderType.GrpcMessage },
434
+ //{ HeaderNames.GrpcStatus, KnownHeaderType.GrpcStatus },
435
+ //{ HeaderNames.GrpcTimeout, KnownHeaderType.GrpcTimeout },
436
+ //{ HeaderNames.KeepAlive, KnownHeaderType.KeepAlive },
437
+ //{ HeaderNames.IfMatch, KnownHeaderType.IfMatch },
438
+ //{ HeaderNames.IfModifiedSince, KnownHeaderType.IfModifiedSince },
439
+ //{ HeaderNames.IfNoneMatch, KnownHeaderType.IfNoneMatch },
440
+ //{ HeaderNames.IfRange, KnownHeaderType.IfRange },
441
+ //{ HeaderNames.IfUnmodifiedSince, KnownHeaderType.IfUnmodifiedSince },
442
+ //{ HeaderNames.LastModified, KnownHeaderType.LastModified },
443
+ //{ HeaderNames.Link, KnownHeaderType.Link },
444
+ //{ HeaderNames.Location, KnownHeaderType.Location },
445
+ //{ HeaderNames.MaxForwards, KnownHeaderType.MaxForwards },
446
+ //{ HeaderNames.Origin, KnownHeaderType.Origin },
447
+ //{ HeaderNames.Pragma, KnownHeaderType.Pragma },
448
+ //{ HeaderNames.ProxyAuthenticate, KnownHeaderType.ProxyAuthenticate },
449
+ //{ HeaderNames.ProxyAuthorization, KnownHeaderType.ProxyAuthorization },
450
+ //{ HeaderNames.ProxyConnection, KnownHeaderType.ProxyConnection },
451
+ //{ HeaderNames.Range, KnownHeaderType.Range },
452
+ //{ HeaderNames.Referer, KnownHeaderType.Referer },
453
+ //{ HeaderNames.RetryAfter, KnownHeaderType.RetryAfter },
454
+ //{ HeaderNames.RequestId, KnownHeaderType.RequestId },
455
+ //{ HeaderNames.SecWebSocketAccept, KnownHeaderType.SecWebSocketAccept },
456
+ //{ HeaderNames.SecWebSocketKey, KnownHeaderType.SecWebSocketKey },
457
+ //{ HeaderNames.SecWebSocketProtocol, KnownHeaderType.SecWebSocketProtocol },
458
+ //{ HeaderNames.SecWebSocketVersion, KnownHeaderType.SecWebSocketVersion },
459
+ //{ HeaderNames.SecWebSocketExtensions, KnownHeaderType.SecWebSocketExtensions },
460
+ //{ HeaderNames.Server, KnownHeaderType.Server },
461
+ //{ HeaderNames.SetCookie, KnownHeaderType.SetCookie },
462
+ //{ HeaderNames.StrictTransportSecurity, KnownHeaderType.StrictTransportSecurity },
463
+ //{ HeaderNames.TE, KnownHeaderType.TE },
464
+ //{ HeaderNames.Trailer, KnownHeaderType.Trailer },
465
+ //{ HeaderNames.TransferEncoding, KnownHeaderType.TransferEncoding },
466
+ //{ HeaderNames.Translate, KnownHeaderType.Translate },
467
+ //{ HeaderNames.TraceParent, KnownHeaderType.TraceParent },
468
+ //{ HeaderNames.TraceState, KnownHeaderType.TraceState },
469
+ //{ HeaderNames.Upgrade, KnownHeaderType.Upgrade },
470
+ //{ HeaderNames.UpgradeInsecureRequests, KnownHeaderType.UpgradeInsecureRequests },
471
+ //{ HeaderNames.UserAgent, KnownHeaderType.UserAgent },
472
+ //{ HeaderNames.Vary, KnownHeaderType.Vary },
473
+ //{ HeaderNames.Via, KnownHeaderType.Via },
474
+ //{ HeaderNames.Warning, KnownHeaderType.Warning },
475
+ //{ HeaderNames.WWWAuthenticate, KnownHeaderType.WWWAuthenticate },
476
+ //{ HeaderNames.XContentTypeOptions, KnownHeaderType.XContentTypeOptions },
477
+ //{ HeaderNames.XFrameOptions, KnownHeaderType.XFrameOptions },
478
+ //{ HeaderNames.XPoweredBy, KnownHeaderType.XPoweredBy },
479
+ //{ HeaderNames.XRequestedWith, KnownHeaderType.XRequestedWith },
480
+ //{ HeaderNames.XUACompatible, KnownHeaderType.XUACompatible },
481
+ //{ HeaderNames.XXSSProtection, KnownHeaderType.XXSSProtection }
482
+ } . ToFrozenDictionary ( StringComparer . OrdinalIgnoreCase ) ;
483
+
484
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
485
+ public static bool GetInternedHeaderType ( string name , out KnownHeaderType type )
486
+ {
487
+ if ( _internedHeaderType . TryGetValue ( name , out type ) )
488
+ {
489
+ return true ;
490
+ }
491
+
492
+ return false ;
493
+ }
494
+ }
495
+
496
+ public enum KnownHeaderType
497
+ {
498
+ Unknown = 0 ,
499
+ Host ,
500
+ //Accept = 1,
501
+ //AcceptCharset = 2,
502
+ //AcceptEncoding = 3,
503
+ //AcceptLanguage,
504
+ //AcceptRanges,
505
+ //AccessControlAllowCredentials,
506
+ //AccessControlAllowHeaders,
507
+ //AccessControlAllowMethods,
508
+ //AccessControlAllowOrigin,
509
+ //AccessControlExposeHeaders,
510
+ //AccessControlMaxAge,
511
+ //AccessControlRequestHeaders,
512
+ //AccessControlRequestMethod,
513
+ //Age,
514
+ //Allow,
515
+ //AltSvc,
516
+ //AltUsed,
517
+ //Authority,
518
+ //Authorization,
519
+ //Baggage,
520
+ //CacheControl,
521
+ //Connection,
522
+ //ContentDisposition,
523
+ //ContentEncoding,
524
+ //ContentLanguage,
525
+ //ContentLength,
526
+ //ContentLocation,
527
+ //ContentMD5,
528
+ //ContentRange,
529
+ //ContentSecurityPolicy,
530
+ //ContentSecurityPolicyReportOnly,
531
+ //ContentType,
532
+ //Cookie,
533
+ //CorrelationContext,
534
+ //Date,
535
+ //DNT,
536
+ //ETag,
537
+ //Expect,
538
+ //Expires,
539
+ //From,
540
+ //GrpcAcceptEncoding,
541
+ //GrpcEncoding,
542
+ //GrpcMessage,
543
+ //GrpcStatus,
544
+ //GrpcTimeout,
545
+ //IfMatch,
546
+ //IfModifiedSince,
547
+ //IfNoneMatch,
548
+ //IfRange,
549
+ //IfUnmodifiedSince,
550
+ //KeepAlive,
551
+ //LastModified,
552
+ //Link,
553
+ //Location,
554
+ //MaxForwards,
555
+ //Method,
556
+ //Origin,
557
+ //Path,
558
+ //Pragma,
559
+ //Protocol,
560
+ //ProxyAuthenticate,
561
+ //ProxyAuthorization,
562
+ //ProxyConnection,
563
+ //Range,
564
+ //Referer,
565
+ //RequestId,
566
+ //SecWebSocketAccept,
567
+ //SecWebSocketKey,
568
+ //SecWebSocketProtocol,
569
+ //SecWebSocketVersion,
570
+ //SecWebSocketExtensions,
571
+ //StrictTransportSecurity,
572
+ //RetryAfter,
573
+ //Scheme,
574
+ //Server,
575
+ //SetCookie,
576
+ //TE,
577
+ //TraceParent,
578
+ //TraceState,
579
+ //Trailer,
580
+ //TransferEncoding,
581
+ //Translate,
582
+ //Upgrade,
583
+ //UpgradeInsecureRequests,
584
+ //UserAgent,
585
+ //Vary,
586
+ //Via,
587
+ //Warning,
588
+ //WWWAuthenticate,
589
+ //XContentTypeOptions,
590
+ //XFrameOptions,
591
+ //XPoweredBy,
592
+ //XRequestedWith,
593
+ //XUACompatible,
594
+ //XXSSProtection,
414
595
}
0 commit comments