libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit b85d48cd952dc2654bb0eb4bbbbbb9d722d2ea04
parent fbb768d9104ddb90ee94c12b5bbcee54fcf72e17
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 28 Oct 2022 15:20:33 +0200

-support mime-types by file extension in demo.c

Diffstat:
Msrc/examples/demo.c | 21+++++++++++++++++++++
1 file changed, 21 insertions(+), 0 deletions(-)

diff --git a/src/examples/demo.c b/src/examples/demo.c @@ -797,6 +797,27 @@ generate_page (void *cls, else #endif /* MHD_HAVE_LIBMAGIC */ mime = NULL; + { + /* Set mime-type by file-extension in some cases */ + const char *ldot = strrchr (&url[1], '.'); + + if (NULL != ldot) + { + if (0 == strcasecmp (ldot, + ".html")) + mime = "text/html"; + if (0 == strcasecmp (ldot, + ".css")) + mime = "text/css"; + if (0 == strcasecmp (ldot, + ".css3")) + mime = "text/css"; + if (0 == strcasecmp (ldot, + ".js")) + mime = "application/javascript"; + } + + } if (NULL == (response = MHD_create_response_from_fd ((size_t) buf.st_size, fd)))