emptygif
ભાષા: ગુજરાતી

બધી ભાષાઓ અને ફ્રેમવર્ક

Wisp Gleam

Wisp માટે Gleam સ્નિપેટ, જે /pixel.gif પરની રિક્વેસ્ટનો જવાબ empty GIF થી આપે છે. GIF સ્ટાર્ટઅપ વખતે એક જ વાર ડિકોડ થાય છે.

Wisp Gleam

ઇન્સ્ટૉલ
gleam add wisp mist gleam_http gleam_erlang
ફાઇલ
pixel.gleam
ચલાવો
gleam run
import gleam/bit_array
import gleam/bytes_tree
import gleam/erlang/process
import gleam/http
import mist
import wisp
import wisp/wisp_mist

pub fn main() {
  wisp.configure_logger()
  let assert Ok(gif) = bit_array.base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

  let assert Ok(_) =
    wisp_mist.handler(handle_request(_, gif), wisp.random_string(64))
    |> mist.new
    |> mist.bind("0.0.0.0")
    |> mist.port(8080)
    |> mist.start

  process.sleep_forever()
}

fn handle_request(req: wisp.Request, gif: BitArray) -> wisp.Response {
  case req.method, req.path {
    http.Get, "/pixel.gif" ->
      wisp.response(200)
      |> wisp.set_header("content-type", "image/gif")
      |> wisp.set_header("cache-control", "no-store")
      |> wisp.set_body(wisp.Bytes(bytes_tree.from_bit_array(gif)))
    _, _ -> wisp.not_found()
  }
}

અમે આ સ્નિપેટ ચલાવ્યો અને તેણે પરત કરેલા બાઇટની સરખામણી કરી.

ચકાસો

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

સત્તાવાર સાઇટ: Wisp