@@ -386,7 +386,7 @@ public PolicyJumpTable BuildJumpTable(int exitDestination, IReadOnlyList<PolicyJ
386386 corsPreflightDestination = corsPreflightDestinations . Single ( ) . Value ;
387387 }
388388
389- return new SingleEntryHttpMethodPolicyJumpTable (
389+ return new HttpMethodSingleEntryPolicyJumpTable (
390390 exitDestination ,
391391 method ,
392392 destination ,
@@ -396,7 +396,7 @@ public PolicyJumpTable BuildJumpTable(int exitDestination, IReadOnlyList<PolicyJ
396396 }
397397 else
398398 {
399- return new DictionaryHttpMethodPolicyJumpTable (
399+ return new HttpMethodDictionaryPolicyJumpTable (
400400 exitDestination ,
401401 destinations ,
402402 corsPreflightExitDestination ,
@@ -445,7 +445,7 @@ private static bool ContainsHttpMethod(List<string> httpMethods, string httpMeth
445445 return false ;
446446 }
447447
448- private static bool IsCorsPreflightRequest ( HttpContext httpContext , string httpMethod , out StringValues accessControlRequestMethod )
448+ public static bool IsCorsPreflightRequest ( HttpContext httpContext , string httpMethod , out StringValues accessControlRequestMethod )
449449 {
450450 accessControlRequestMethod = default ;
451451 var headers = httpContext . Request . Headers ;
@@ -456,91 +456,6 @@ private static bool IsCorsPreflightRequest(HttpContext httpContext, string httpM
456456 ! StringValues . IsNullOrEmpty ( accessControlRequestMethod ) ;
457457 }
458458
459- private sealed class SingleEntryHttpMethodPolicyJumpTable : PolicyJumpTable
460- {
461- private readonly int _exitDestination ;
462- private readonly string _method ;
463- private readonly int _destination ;
464- private readonly int _corsPreflightExitDestination ;
465- private readonly int _corsPreflightDestination ;
466-
467- private readonly bool _supportsCorsPreflight ;
468-
469- public SingleEntryHttpMethodPolicyJumpTable (
470- int exitDestination ,
471- string method ,
472- int destination ,
473- bool supportsCorsPreflight ,
474- int corsPreflightExitDestination ,
475- int corsPreflightDestination )
476- {
477- _exitDestination = exitDestination ;
478- _method = method ;
479- _destination = destination ;
480- _supportsCorsPreflight = supportsCorsPreflight ;
481- _corsPreflightExitDestination = corsPreflightExitDestination ;
482- _corsPreflightDestination = corsPreflightDestination ;
483- }
484-
485- public override int GetDestination ( HttpContext httpContext )
486- {
487- var httpMethod = httpContext . Request . Method ;
488- if ( _supportsCorsPreflight && IsCorsPreflightRequest ( httpContext , httpMethod , out var accessControlRequestMethod ) )
489- {
490- return CompareMethod ( accessControlRequestMethod , _method ) ? _corsPreflightDestination : _corsPreflightExitDestination ;
491- }
492-
493- return CompareMethod ( httpMethod , _method ) ? _destination : _exitDestination ;
494-
495- static bool CompareMethod ( string requestMethod , string endpointMethod )
496- {
497- // Known methods (GET, POST, PUT, etc) will match by reference.
498- // Custom methods fallback to ignore case compare.
499- return ReferenceEquals ( requestMethod , endpointMethod ) || StringComparer . OrdinalIgnoreCase . Equals ( requestMethod , endpointMethod ) ;
500- }
501- }
502- }
503-
504- private sealed class DictionaryHttpMethodPolicyJumpTable : PolicyJumpTable
505- {
506- private readonly int _exitDestination ;
507- private readonly Dictionary < string , int > ? _destinations ;
508- private readonly int _corsPreflightExitDestination ;
509- private readonly Dictionary < string , int > ? _corsPreflightDestinations ;
510-
511- private readonly bool _supportsCorsPreflight ;
512-
513- public DictionaryHttpMethodPolicyJumpTable (
514- int exitDestination ,
515- Dictionary < string , int > ? destinations ,
516- int corsPreflightExitDestination ,
517- Dictionary < string , int > ? corsPreflightDestinations )
518- {
519- _exitDestination = exitDestination ;
520- _destinations = destinations ;
521- _corsPreflightExitDestination = corsPreflightExitDestination ;
522- _corsPreflightDestinations = corsPreflightDestinations ;
523-
524- _supportsCorsPreflight = _corsPreflightDestinations != null && _corsPreflightDestinations . Count > 0 ;
525- }
526-
527- public override int GetDestination ( HttpContext httpContext )
528- {
529- int destination ;
530-
531- var httpMethod = httpContext . Request . Method ;
532- if ( _supportsCorsPreflight && IsCorsPreflightRequest ( httpContext , httpMethod , out var accessControlRequestMethod ) )
533- {
534- return _corsPreflightDestinations ! . TryGetValue ( accessControlRequestMethod , out destination )
535- ? destination
536- : _corsPreflightExitDestination ;
537- }
538-
539- return _destinations != null &&
540- _destinations . TryGetValue ( httpMethod , out destination ) ? destination : _exitDestination ;
541- }
542- }
543-
544459 private class HttpMethodMetadataEndpointComparer : EndpointMetadataComparer < IHttpMethodMetadata >
545460 {
546461 protected override int CompareMetadata ( IHttpMethodMetadata ? x , IHttpMethodMetadata ? y )
0 commit comments