commit - df79b4c1d5c7dda510accf2d407e318b33bb936d
commit + 6119e13e8aa794988b3875614a0a2c3ce0f07e7b
blob - 76dbe3d3223be14a39a0548f58b60449c9682224
blob + 49639b6d66784f31aabadf6115298efea2d42fd5
--- ChangeLog
+++ ChangeLog
2021-01-19 Omar Polo <op@omarpolo.com>
* parse.y (servopt): add "lang" server option
+ (servopt): moving "default type" from global options to server options
* Dockerfile: add a dockerfile
blob - 7f70c2b55cbb3a80f2ab364659a119508e8572d7
blob + 221de079917342c19956ebf943a0a2ca2cb33270
--- gmid.1
+++ gmid.1
to the given
.Ar mime-type .
Both argument are strings.
-.It Ic default type Ar string
-Set the default media type that is used if the media type for a
-specified extension is not found.
-If not specified, the
-.Ic default type
-is set to
-.Dq application/octet-stream .
.El
.Ss Servers
Every virtual host is defined by a
is a prefix of the user request string.
An empty path "" will effectively enable the execution of any file
with the executable bit set inside the root directory.
+.It Ic default type Ar string
+Set the default media type that is used if the media type for a
+specified extension is not found.
+If not specified, the
+.Ic default type
+is set to
+.Dq application/octet-stream .
.It Ic lang Ar string
Specify the language tag for the text/gemini content served.
If not specified, no
blob - 892399c18a88cc5f36b94c778b71a63ca9a6fa7d
blob + de132601e38ef77d2a1cfd8e8177b9dab9c19a80
--- gmid.h
+++ gmid.h
const char *cgi;
char *lang;
int dirfd;
+ char *default_mime;
};
extern struct vhost hosts[HOSTSLEN];
};
struct mimes {
- char *def;
struct etm *t;
size_t len;
size_t cap;
/* mime.c */
void init_mime(void);
-void set_default_mime(const char*);
void add_mime(const char*, const char*);
void load_default_mime(void);
int load_mime_file(const char*);
-const char *mime(const char*);
+const char *mime(struct vhost*, const char*);
/* server.c */
int check_path(struct client*, const char*, int*);
blob - 35ff72e47d9e280b831795a9d008ae877ae0a5c3
blob + f81a813314e549d370531b0bac2298603550c897
--- mime.c
+++ mime.c
init_mime(void)
{
conf.mimes.len = 0;
- conf.mimes.cap = 2;
+ conf.mimes.cap = 16;
conf.mimes.t = calloc(conf.mimes.cap, sizeof(struct etm));
if (conf.mimes.t == NULL)
fatal("calloc: %s", strerror(errno));
-
- conf.mimes.def = strdup("application/octet-stream");
- if (conf.mimes.def == NULL)
- fatal("strdup: %s", strerror(errno));
-
}
-void
-set_default_mime(const char *m)
-{
- free(conf.mimes.def);
- if ((conf.mimes.def = strdup(m)) == NULL)
- fatal("strdup: %s", strerror(errno));
-}
-
/* register mime for the given extension */
void
add_mime(const char *mime, const char *ext)
}
const char *
-mime(const char *path)
+mime(struct vhost *host, const char *path)
{
- const char *ext;
+ const char *def, *ext;
struct etm *t;
+ if ((def = host->default_mime) == NULL)
+ def = "application/octet-stream";
+
if ((ext = path_ext(path)) == NULL)
- return conf.mimes.def;
+ return def;
for (t = conf.mimes.t; t->mime != NULL; ++t)
if (!strcmp(ext, t->ext))
return t->mime;
- return conf.mimes.def;
+ return def;
}
blob - 36c3eac30f4c8165e2dde500514ba5b56878c2ae
blob + 3fefb0b3fce26d73fcb0ea4e018576a6fbe5661d
--- parse.y
+++ parse.y
errx(1, "invalid protocols string \"%s\"", $2);
}
| TMIME TSTRING TSTRING { add_mime($2, $3); }
- | TDEFAULT TTYPE TSTRING { set_default_mime($3); }
;
vhosts : /* empty */
if (*host->cgi == '/')
host->cgi++;
}
+ | TDEFAULT TTYPE TSTRING {
+ free(host->default_mime);
+ host->default_mime = $3;
+ }
| TLANG TSTRING {
free(host->lang);
host->lang = $2;
}
;
-
blob - 4401bf901bd7062589e6c2957e1a750fd54fecf0
blob + 3d542f91370f207987d5f7384bb98dfc01c66e60
--- server.c
+++ server.c
return 0;
}
c->i = c->buf;
- return start_reply(fds, c, SUCCESS, mime(fpath));
+ return start_reply(fds, c, SUCCESS, mime(c->host, fpath));
case FILE_DIRECTORY:
LOGD(c, "%s is a directory, trying %s/index.gmi", fpath, fpath);