/// <summary> /// Adds a custom <see cref="IServerTimingMetricFilter"/>. /// </summary> /// <param name="options">The <see cref="ServerTimingOptions"/> to modify.</param> /// <param name="filter">The function used for inspecting and modifying the collection of metrics.</param> public static void AddCustomMetricFilter(this ServerTimingOptions options, Func <HttpContext, ICollection <ServerTimingMetric>, bool> filter) => options.Filters.Add(new CustomServerTimingMetricFilter(filter));
/// <summary> /// Instantiates a new <see cref="ServerTimingMiddleware"/>. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="options">Server timing configuration options</param> public ServerTimingMiddleware(RequestDelegate next, ServerTimingOptions options) { _next = next ?? throw new ArgumentNullException(nameof(next)); _timingAllowOriginHeaderValue = (options.AllowedOrigins is null) ? null : new TimingAllowOriginHeaderValue(options.AllowedOrigins).ToString(); _serverTimingMetricFilters = options.Filters ?? new List <IServerTimingMetricFilter>(); }
/// <summary> /// Adds <see cref="IServerTimingMetricFilter"/> which will remove all metrics unless request comes from IP address which falls within the specified range. /// </summary> /// <param name="options">The <see cref="ServerTimingOptions"/> to modify.</param> /// <param name="lowerInclusive">The lower (inclusive) bound of the IP addresses range.</param> /// <param name="upperInclusive">The upper (inclusive) bound of the IP addresses range.</param> public static void RestrictMetricsToIpRange(this ServerTimingOptions options, IPAddress lowerInclusive, IPAddress upperInclusive) => options.Filters.Add(new IPRangeMetricFilter(lowerInclusive, upperInclusive));
/// <summary> /// Adds <see cref="IServerTimingMetricFilter"/> which will remove all metrics unless request comes from IP address which falls within the specified range. /// </summary> /// <param name="options">The <see cref="ServerTimingOptions"/> to modify.</param> /// <param name="lowerInclusive">The lower (inclusive) bound of the IP addresses range.</param> /// <param name="upperInclusive">The upper (inclusive) bound of the IP addresses range.</param> public static void RestrictMetricsToIpRange(this ServerTimingOptions options, string lowerInclusive, string upperInclusive) => options.Filters.Add(new IPRangeMetricFilter(IPAddress.Parse(lowerInclusive), IPAddress.Parse(upperInclusive)));
/// <summary> /// Adds <see cref="IServerTimingMetricFilter"/> which will remove all metrics unless request comes from specific IP address. /// </summary> /// <param name="options">The <see cref="ServerTimingOptions"/> to modify.</param> /// <param name="address">The IP Address which is allowed to receive the metrics.</param> public static void RestrictMetricsToIp(this ServerTimingOptions options, string address) => RestrictMetricsToIpRange(options, address, address);
/// <summary> /// Adds <see cref="IServerTimingMetricFilter"/> which will remove the descriptions from all metrics unless an application is running in development environment. /// </summary> /// <param name="options">The <see cref="ServerTimingOptions"/> to modify.</param> /// <param name="hostingEnvironment">The <see cref="Microsoft.AspNetCore.Hosting.IHostingEnvironment"/> used to determine the hosting environment an application is running in</param> public static void RemoveDescriptionsOutsideDevelopment(this ServerTimingOptions options, Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment) { options.Filters.Add(new RestrictDescriptionsToDevelopmentMetricFilter(hostingEnvironment)); }
/// <summary> /// Adds <see cref="IServerTimingMetricFilter"/> which will remove the descriptions from all metrics unless an application is running in development environment. /// </summary> /// <param name="options">The <see cref="ServerTimingOptions"/> to modify.</param> /// <param name="hostEnvironment">The <see cref="Microsoft.Extensions.Hosting.IHostEnvironment"/> used to determine the hosting environment an application is running in.</param> public static void RestrictDescriptionsToDevelopment(this ServerTimingOptions options, Microsoft.Extensions.Hosting.IHostEnvironment hostEnvironment) { options.Filters.Add(new RestrictDescriptionsToDevelopmentMetricFilter(hostEnvironment)); }