ASP.NET Core Minimal API C#
適用於 ASP.NET Core Minimal API 的 C# 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
ASP.NET Core Minimal API C#
var gif = Convert.FromBase64String("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
var app = WebApplication.CreateBuilder(args).Build();
app.MapGet("/pixel.gif", (HttpResponse response) =>
{
response.Headers.CacheControl = "no-store";
return TypedResults.Bytes(gif, "image/gif");
});
app.Run("http://0.0.0.0:8080");
我們執行了這段程式碼,並比對了它回傳的位元組。
驗證
curl -sI http://localhost:8080/pixel.gif
官方網站: ASP.NET Core Minimal API