Tous les langages et frameworks
FastEndpoints C#
Un extrait C# pour FastEndpoints qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.
FastEndpoints C#
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);
}
}
Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.
Vérifier
curl -sI http://localhost:8080/pixel.gif