emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

HTTP.jl Julia

Snippet Julia untuk HTTP.jl yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

HTTP.jl Julia

Instal
julia -e 'using Pkg; Pkg.add("HTTP")'
File
server.jl
Jalankan
julia server.jl
using Base64
using HTTP

const GIF = base64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
const HEADERS = ["Content-Type" => "image/gif", "Cache-Control" => "no-store"]

router = HTTP.Router()
HTTP.register!(router, "GET", "/pixel.gif", _ -> HTTP.Response(200, HEADERS, GIF))

HTTP.serve(router, "0.0.0.0", 8080)

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: HTTP.jl

Lainnya dalam Julia