emptygif
Wika: Filipino

Lahat ng language at framework

Loco Rust

Isang Rust snippet para sa Loco na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

Loco Rust

I-install
cargo install loco && loco new
File
src/controllers/pixel.rs
Patakbuhin
cargo loco start
// src/controllers/pixel.rs - register it in src/app.rs:
//   AppRoutes::with_default_routes().add_route(controllers::pixel::routes())
use axum::http::header;
use loco_rs::prelude::*;

const GIF: &[u8] = &[0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x21, 0xf9, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x3b];

async fn pixel() -> impl IntoResponse {
    (
        [
            (header::CONTENT_TYPE, "image/gif"),
            (header::CACHE_CONTROL, "no-store"),
        ],
        GIF,
    )
}

pub fn routes() -> Routes {
    Routes::new().add("/pixel.gif", get(pixel))
}

Kinompile o tinype-check namin ang snippet na ito.

Suriin

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

Opisyal na site: Loco

Iba pa sa Rust