Commit 96fa2377 authored by Adam Štěpánek's avatar Adam Štěpánek
Browse files

Add GNU Terry Pratchett

parent 51a5d5c5
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;

namespace Kafe.Api.Middleware;

public class ClacksMiddleware : IMiddleware
{
    public const string HeaderName = "X-Clacks-Overhead";
    public const string HeaderValue = "GNU Terry Pratchett";

    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
    {
        context.Response.OnStarting(() =>
        {
            context.Response.Headers.TryAdd(HeaderName, HeaderValue);
            return Task.CompletedTask;
        });

        await next(context);
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ using Npgsql;
using System.Globalization;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Kafe.Api.Middleware;

namespace Kafe.Api;

@@ -220,10 +221,13 @@ public class Startup
        services.RemoveAll<IProblemDetailsWriter>();
        services.AddSingleton<IProblemDetailsWriter, KafeProblemDetailsWriter>();
        services.AddSingleton<IProblemDetailsService, KafeProblemDetailsService>();
        services.AddSingleton<ClacksMiddleware>();
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseMiddleware<ClacksMiddleware>();

        app.UseForwardedHeaders();

        app.UseHttpsRedirection();
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ http {
    sendfile           on;
    keepalive_timeout  65;
    add_header 'Cache-Control' "no-cache";
    add_header 'X-Clacks-Overhead' "GNU Terry Pratchett";

    server {
        listen       80;