// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseDefaultFiles(new DefaultFilesOptions()
            {
                DefaultFileNames = new List <string> {
                    "reporting-api.html"
                }
            });

            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    ReportToHeaderValue reportToValue = new ReportToHeaderValue();
                    reportToValue.Endpoints.Add(new ReportToEndpoint("https://localhost:5001/report-to-endpoint"));

                    ctx.Context.Response.AddReportToResponseHeader(reportToValue);
                }
            });

            app.MapReportToEndpoint("/report-to-endpoint");

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("-- Demo.AspNetCore.ReportTo --");
            });
        }
Exemplo n.º 2
0
        public static void AddReportToResponseHeader(this HttpResponse response, ReportToHeaderValue reportTo)
        {
            string reportToHeaderValue = reportTo?.ToString();

            if (!String.IsNullOrWhiteSpace(reportToHeaderValue))
            {
                if (response.Headers.ContainsKey(HeaderNames.ReportTo))
                {
                    response.Headers[HeaderNames.ReportTo] = (StringValues)response.Headers[HeaderNames.ReportTo].Append(reportToHeaderValue);
                }
                else
                {
                    response.Headers[HeaderNames.ReportTo] = reportToHeaderValue;
                }
            }
        }