/// <summary>
        /// Adds middleware for using ExpectCT, which adds the Expect-CT header.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
        /// <param name="optionsAction">A delegate used for setting up the <see cref="ExpectCtOptionsBuilder"/>.</param>
        public static IApplicationBuilder UseExpectCt(this IApplicationBuilder app, Action <ExpectCtOptionsBuilder> optionsAction)
        {
            ExpectCtOptionsBuilder builder = new ExpectCtOptionsBuilder();

            optionsAction(builder);
            ExpectCtOptions options = builder.Build();

            return(app.UseMiddleware <ExpectCtMiddleware>(options));
        }
Exemplo n.º 2
0
        public ExpectCtMiddleware(RequestDelegate next, ExpectCtOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.next = next;

            List <string> parts = new List <string>();

            if (options.ReportUri != null)
            {
                parts.Add($"report-uri=\"{options.ReportUri}\"");
            }
            if (options.Enforce)
            {
                parts.Add("enforce");
            }
            parts.Add($"max-age={options.MaxAge}");
            headerValue = string.Join(", ", parts);
        }
 internal ExpectCtOptionsBuilder()
 {
     options = new ExpectCtOptions();
 }