Tous les langages et frameworks
Helidon SE Java
Un extrait Java pour Helidon SE qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.
Helidon SE Java
import io.helidon.http.HeaderNames;
import io.helidon.webserver.WebServer;
import java.util.Base64;
public class Pixel {
private static final byte[] GIF = Base64.getDecoder().decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
public static void main(String[] args) {
WebServer.builder()
.port(8080)
.routing(routing -> routing.get("/pixel.gif", (req, res) -> {
res.header(HeaderNames.CONTENT_TYPE, "image/gif");
res.header(HeaderNames.CACHE_CONTROL, "no-store");
res.send(GIF);
}))
.build()
.start();
}
}
Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.
Vérifier
curl -sI http://localhost:8080/pixel.gif