emptygif
Language: English

All languages and frameworks

Javalin Java

A Java snippet for Javalin that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Javalin Java

Install
implementation("io.javalin:javalin:7.2.3")
File
Pixel.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);
    }
}

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Javalin

More in Java