Javalin Java
適用於 Javalin 的 Java 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
Javalin Java
import io.javalin.Javalin;
import java.util.Base64;
public class Pixel {
private static final byte[] GIF = Base64.getDecoder().decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
public static void main(String[] args) {
Javalin.create(config -> {
config.routes.get("/pixel.gif", ctx -> {
ctx.contentType("image/gif");
ctx.header("Cache-Control", "no-store");
ctx.result(GIF);
});
}).start(8080);
}
}
我們執行了這段程式碼,並比對了它回傳的位元組。
驗證
curl -sI http://localhost:8080/pixel.gif