n_http_mime: media types from extensions, last segment only, query ignored, case-insensitive, NULL when unknown
n_http_mime: media types from extensions, last segment only, query ignored, case-insensitive, NULL when unknown
- Author
- Castagnier Mickael
- Version
- 1.0
- Date
- 23/10/2026
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int opt = 0;
while ((opt = getopt(argc, argv, "V:")) != -1) {
if (opt == 'V') {
} else {
return -1;
}
}
return 0;
}
static void expect_type(
const char* path,
const char* want) {
if ((want == NULL) != (got == NULL) || (want && strcmp(got, want) != 0)) {
n_log(
LOG_ERR,
"FAIL: %s gave %s, not %s", path, got ? got :
"NULL", want ? want :
"NULL");
}
}
int main(
int argc,
char** argv) {
fprintf(stderr, "usage: %s [-V LOG_LEVEL]\n", argv[0]);
return 1;
}
}
expect_type(
"/Games/BlockBlaster/index.HTML?x=1#top",
"text/html");
expect_type(
"/media/0123456789abcdef/960/photo.webp",
"image/webp");
expect_type(
"favicon.ico",
"image/vnd.microsoft.icon");
expect_type(
"site.webmanifest",
"application/manifest+json");
}
return 1;
}
return 0;
}
void process_args(int argc, char **argv)
static void expect_type(const char *path, const char *want)
path maps to want (NULL: no type)
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_NOTICE
normal but significant condition
int n_http_mime_table_check(void)
check that the built-in table is sorted, as its lookup requires
const char * n_http_mime_type(const char *path, size_t len)
media type for a path or file name, from its extension
Common headers and low-level functions & define.
Media type of a file from its extension, for a static file server.