emptygif
Idioma: Español

Todos los lenguajes y frameworks

FastEndpoints C#

Un fragmento en C# para FastEndpoints que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

FastEndpoints C#

Instalar
dotnet add package FastEndpoints
Archivo
Program.cs
Ejecutar
dotnet run
using FastEndpoints;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddFastEndpoints();

var app = builder.Build();
app.UseFastEndpoints();
app.Run("http://0.0.0.0:8080");

sealed class PixelEndpoint : EndpointWithoutRequest
{
    static readonly byte[] Gif = Convert.FromBase64String("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");

    public override void Configure()
    {
        Get("/pixel.gif");
        AllowAnonymous();
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        HttpContext.Response.Headers.CacheControl = "no-store";
        await Send.BytesAsync(Gif, contentType: "image/gif", cancellation: ct);
    }
}

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

curl -sI http://localhost:8080/pixel.gif

Sitio oficial: FastEndpoints

Más en C#