Lahat ng language at framework
Racket web server Racket
Isang Racket snippet para sa Racket web server na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.
Racket web server Racket
#lang racket/base
(require net/base64
web-server/http
web-server/servlet-env)
(define gif (base64-decode #"R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="))
(define (pixel req)
(response/full 200 #"OK" (current-seconds) #"image/gif"
(list (header #"Cache-Control" #"no-store"))
(list gif)))
;; serve/servlet only dispatches requests whose path is exactly #:servlet-path.
(serve/servlet pixel
#:port 8080
#:listen-ip #f
#:servlet-path "/pixel.gif"
#:command-line? #t)
Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.
Suriin
curl -sI http://localhost:8080/pixel.gif