emptygif
மொழி: தமிழ்

அனைத்து மொழிகளும் ஃப்ரேம்வொர்க்குகளும்

Mongoose C

/pixel.gif க்கு வரும் ரெக்வெஸ்ட்களுக்கு empty GIF மூலம் பதிலளிக்கும், Mongoose க்கான C ஸ்னிப்பெட். GIF ஸ்டார்ட்அப்பில் ஒருமுறை மட்டுமே டீகோட் செய்யப்படுகிறது.

Mongoose C

இன்ஸ்டால்
curl -LO https://raw.githubusercontent.com/cesanta/mongoose/master/mongoose.c -LO https://raw.githubusercontent.com/cesanta/mongoose/master/mongoose.h
ஃபைல்
main.c
ரன்
cc -O2 main.c mongoose.c -o pixel && ./pixel
#include "mongoose.h"

static const unsigned char GIF[] = {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};

static void handler(struct mg_connection *c, int ev, void *ev_data) {
    if (ev != MG_EV_HTTP_MSG) return;
    struct mg_http_message *hm = (struct mg_http_message *) ev_data;
    if (mg_strcmp(hm->uri, mg_str("/pixel.gif")) == 0) {
        mg_printf(c,
                  "HTTP/1.1 200 OK\r\n"
                  "Content-Type: image/gif\r\n"
                  "Content-Length: %d\r\n"
                  "Cache-Control: no-store\r\n\r\n",
                  (int) sizeof GIF);
        mg_send(c, GIF, sizeof GIF);
    } else {
        mg_http_reply(c, 404, "", "Not Found\n");
    }
}

int main(void) {
    struct mg_mgr mgr;
    mg_mgr_init(&mgr);
    mg_http_listen(&mgr, "http://0.0.0.0:8080", handler, NULL);
    for (;;) mg_mgr_poll(&mgr, 1000);
}

இந்த ஸ்னிப்பெட்டை ரன் செய்து, அது திருப்பித் தந்த பைட்களை ஒப்பிட்டுப் பார்த்தோம்.

சரிபார்

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

அதிகாரப்பூர்வ சைட்: Mongoose

C இல் மேலும்