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

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

GNU libmicrohttpd C

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

GNU libmicrohttpd C

ઇન્સ્ટૉલ
sudo apt install libmicrohttpd-dev
ફાઇલ
main.c
ચલાવો
cc -O2 main.c -o pixel -lmicrohttpd && ./pixel
#include <microhttpd.h>
#include <string.h>
#include <unistd.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 enum MHD_Result handler(void *cls, struct MHD_Connection *conn, const char *url,
                               const char *method, const char *version, const char *upload_data,
                               size_t *upload_data_size, void **req_cls) {
    (void) cls; (void) version; (void) upload_data; (void) upload_data_size; (void) req_cls;
    int found = strcmp(method, "GET") == 0 && strcmp(url, "/pixel.gif") == 0;
    struct MHD_Response *res = found
        ? MHD_create_response_from_buffer_static(sizeof GIF, GIF)
        : MHD_create_response_from_buffer_static(0, "");
    if (found) {
        MHD_add_response_header(res, "Content-Type", "image/gif");
        MHD_add_response_header(res, "Cache-Control", "no-store");
    }
    enum MHD_Result ret = MHD_queue_response(conn, found ? MHD_HTTP_OK : MHD_HTTP_NOT_FOUND, res);
    MHD_destroy_response(res);
    return ret;
}

int main(void) {
    struct MHD_Daemon *daemon = MHD_start_daemon(
        MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 8080, NULL, NULL,
        &handler, NULL, MHD_OPTION_END);
    if (daemon == NULL) return 1;
    pause(); // the daemon serves requests on its own thread
    MHD_stop_daemon(daemon);
    return 0;
}

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

ચકાસો

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

સત્તાવાર સાઇટ: GNU libmicrohttpd

C માં વધુ