Mist Gleam
/pixel.gif కు వచ్చే రిక్వెస్ట్లకు empty GIF తో జవాబిచ్చే, Mist కోసం Gleam స్నిపెట్. GIF స్టార్టప్లో ఒక్కసారే డీకోడ్ అవుతుంది.
Mist Gleam
import gleam/bit_array
import gleam/bytes_tree
import gleam/erlang/process
import gleam/http
import gleam/http/request.{type Request}
import gleam/http/response.{type Response}
import mist.{type Connection, type ResponseData}
pub fn main() {
let assert Ok(gif) = bit_array.base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
let assert Ok(_) =
fn(req: Request(Connection)) -> Response(ResponseData) {
case req.method, req.path {
http.Get, "/pixel.gif" ->
response.new(200)
|> response.set_header("content-type", "image/gif")
|> response.set_header("cache-control", "no-store")
|> response.set_body(mist.Bytes(bytes_tree.from_bit_array(gif)))
_, _ ->
response.new(404)
|> response.set_body(mist.Bytes(bytes_tree.new()))
}
}
|> mist.new
|> mist.bind("0.0.0.0")
|> mist.port(8080)
|> mist.start
process.sleep_forever()
}
మేము ఈ స్నిపెట్ను రన్ చేసి, అది తిరిగి ఇచ్చిన బైట్లను పోల్చి చూశాం.
చెక్ చేయండి
curl -sI http://localhost:8080/pixel.gif