emptygif
भाषा: हिन्दी

सभी भाषाएँ और फ़्रेमवर्क

Loco Rust

Loco के लिए Rust स्निपेट, जो /pixel.gif पर आने वाली रिक्वेस्ट का जवाब empty GIF से देता है। GIF स्टार्टअप पर एक ही बार डिकोड होता है।

Loco Rust

इंस्टॉल
cargo install loco && loco new
फ़ाइल
src/controllers/pixel.rs
चलाएँ
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))
}

हमने इस स्निपेट को कंपाइल या टाइप-चेक किया।

जाँचें

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

आधिकारिक साइट: Loco

Rust में और