Add --default-mimetype flag.

This commit is contained in:
Emil Mikulic 2015-05-19 21:40:26 +10:00
parent e9aeaba7fe
commit c4c0034242
3 changed files with 14 additions and 3 deletions

View File

@ -314,7 +314,8 @@ static const char *default_extension_map[] = {
NULL
};
static const char default_mimetype[] = "application/octet-stream";
static const char octet_stream[] = "application/octet-stream";
static const char *default_mimetype = octet_stream;
/* Prototypes. */
static void poll_recv_request(struct connection *conn);
@ -891,6 +892,9 @@ static void usage(const char *argv0) {
"\t\tDo not serve listing if directory is requested.\n\n");
printf("\t--mimetypes filename (optional)\n"
"\t\tParses specified file for extension-MIME associations.\n\n");
printf("\t--default-mimetype string (optional, default: %s)\n"
"\t\tFiles with unknown extensions are served as this mimetype.\n\n",
octet_stream);
printf("\t--uid uid/uname, --gid gid/gname (default: don't privdrop)\n"
"\t\tDrops privileges to given uid:gid after initialization.\n\n");
printf("\t--pidfile filename (default: no pidfile)\n"
@ -1008,6 +1012,11 @@ static void parse_commandline(const int argc, char *argv[]) {
errx(1, "missing filename after --mimetypes");
parse_extension_map_file(argv[i]);
}
else if (strcmp(argv[i], "--default-mimetype") == 0) {
if (++i >= argc)
errx(1, "missing string after --default-mimetype");
default_mimetype = argv[i];
}
else if (strcmp(argv[i], "--uid") == 0) {
struct passwd *p;
if (++i >= argc)

View File

@ -77,7 +77,9 @@ echo "test/this-gets-replaced ap2" >> $DIR/mimemap
echo "# this is a comment" >> $DIR/mimemap
printf "test/type3\\tapp3\r\n" >> $DIR/mimemap
echo "test/type2 ap2" >> $DIR/mimemap
./a.out $DIR --port $PORT --mimetypes $DIR/mimemap >/dev/null &
./a.out $DIR --port $PORT \
--mimetypes $DIR/mimemap \
--default-mimetype test/default >/dev/null &
PID=$!
kill -0 $PID || exit 1
python test_mimemap.py

View File

@ -11,7 +11,7 @@ class TestMimemap(TestHelper):
self.files = [ ("test-file.a1", "test/type1"),
("test-file.ap2", "test/type2"),
("test-file.app3", "test/type3"),
("test-file.appp4", "application/octet-stream") ]
("test-file.appp4", "test/default") ]
for fn, _ in self.files:
open(WWWROOT + "/" + fn, "w").write(self.data)