예제 #1
0
 public static ICorsPolicySource ThatApplies(
     this IEnumerable <ICorsPolicySource> sources, CorsConfiguration corsConfiguration,
     ActionDescriptor actionDescriptor, Configuration configuration,
     HttpConfiguration httpConfiguration)
 {
     return(corsConfiguration.PolicySources.ThatApply(sources,
                                                      new ActionConfigurationContext(configuration, httpConfiguration,
                                                                                     actionDescriptor.Action, actionDescriptor.Route))
            .FirstOrDefault());
 }
예제 #2
0
 public CorsBehavior(IBehaviorChain behaviorChain,
                     ICorsEngine corsEngine, CorsConfiguration corsConfiguration,
                     ActionDescriptor actionDescriptor, HttpRequestMessage requestMessage,
                     IEnumerable <ICorsPolicySource> policySources, Configuration configuration,
                     HttpConfiguration httpConfiguration) : base(behaviorChain)
 {
     _configuration     = configuration;
     _httpConfiguration = httpConfiguration;
     _corsEngine        = corsEngine;
     _corsConfiguration = corsConfiguration;
     _actionDescriptor  = actionDescriptor;
     _requestMessage    = requestMessage;
     _policySources     = policySources;
 }
예제 #3
0
        public static ConfigurationDsl EnableCors(
            this ConfigurationDsl configuration, Action <CorsConfigurationDsl> configure = null)
        {
            var corsConfiguration = new CorsConfiguration();

            configure?.Invoke(new CorsConfigurationDsl(corsConfiguration));
            return(configuration
                   .ConfigureHttpRouteDecorators(x => x
                                                 .Append <OptionsRouteDecorator>(a => corsConfiguration.PolicySources.ThatApplyTo(a).Any()))
                   .ConfigureBehaviors(x => x
                                       .Prepend <CorsBehavior>(a => corsConfiguration.PolicySources.ThatApplyTo(a).Any()))
                   .ConfigureRegistry(x => x
                                      .Register(corsConfiguration)
                                      .RegisterPlugin(corsConfiguration.CorsEngine)
                                      .RegisterPlugins(corsConfiguration.PolicySources)));
        }
예제 #4
0
 public CorsConfigurationDsl(CorsConfiguration configuration)
 {
     _configuration = configuration;
 }