/// <summary>
 /// A middleware used to filter requests by their Host header.
 /// </summary>
 /// <param name="next"></param>
 /// <param name="logger"></param>
 /// <param name="options"></param>
 public HostFilteringMiddleware(RequestDelegate next, ILogger <HostFilteringMiddleware> logger,
                                IOptions <HostFilteringOptions> options)
 {
     _next    = next ?? throw new ArgumentNullException(nameof(next));
     _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
     _options = options?.Value ?? throw new ArgumentNullException(nameof(options));
 }
Example #2
0
 /// <summary>
 /// A middleware used to filter requests by their Host header.
 /// </summary>
 /// <param name="next"></param>
 /// <param name="logger"></param>
 /// <param name="optionsMonitor"></param>
 public HostFilteringMiddleware(RequestDelegate next, ILogger <HostFilteringMiddleware> logger,
                                IOptionsMonitor <HostFilteringOptions> optionsMonitor)
 {
     _next           = next ?? throw new ArgumentNullException(nameof(next));
     _logger         = logger ?? throw new ArgumentNullException(nameof(logger));
     _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor));
     _options        = _optionsMonitor.CurrentValue;
     _optionsMonitor.OnChange(options =>
     {
         // Clear the cached settings so the next EnsureConfigured will re-evaluate.
         _options              = options;
         _allowedHosts         = new List <StringSegment>();
         _allowAnyNonEmptyHost = null;
     });
 }