emptygif
Language: English

All languages and frameworks

Jooby Java

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

Jooby Java

Install
implementation("io.jooby:jooby-netty:4.5.4")
File
App.java
Run
./gradlew run
import io.jooby.Jooby;
import io.jooby.MediaType;
import io.jooby.ServerOptions;
import io.jooby.netty.NettyServer;
import java.util.Base64;

public class App extends Jooby {
    static final byte[] GIF = Base64.getDecoder().decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");

    {
        get("/pixel.gif", ctx -> ctx
                .setResponseType(MediaType.valueOf("image/gif"))
                .setResponseHeader("Cache-Control", "no-store")
                .send(GIF));
    }

    public static void main(String[] args) {
        runApp(args, new NettyServer(new ServerOptions().setPort(8080)), App::new);
    }
}

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Jooby

More in Java