mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 06:51:04 +08:00
allow to define a default mime-type to use when lookup in the internal table fails
instead of always returning 'text/plain' To allow setting a different default mime-type the mg_get_mime_type() api has been extended to require an mg_server parameter. Note that using a static global as default mime type wouldn't have allowed us to control it via a configuration option because there is not global initialization phase and configuration options are provided (and specific) to each server instance. This means that different servers can be configured to use a different default mime-type (which is also a desired behaviour in many scenarios) when lookup fails.
This commit is contained in:
parent
2392156fd4
commit
45f6612096
@ -220,6 +220,7 @@ enum {
|
||||
CGI_PATTERN, DAV_AUTH_FILE, DOCUMENT_ROOT, ENABLE_DIRECTORY_LISTING,
|
||||
#endif
|
||||
EXTRA_MIME_TYPES,
|
||||
DEFAULT_MIME_TYPE,
|
||||
#ifndef MONGOOSE_NO_FILESYSTEM
|
||||
GLOBAL_AUTH_FILE,
|
||||
#endif
|
||||
@ -249,6 +250,7 @@ static const char *static_config_options[] = {
|
||||
"enable_directory_listing", "yes",
|
||||
#endif
|
||||
"extra_mime_types", NULL,
|
||||
"default_mime_type", "text/plain",
|
||||
#ifndef MONGOOSE_NO_FILESYSTEM
|
||||
"global_auth_file", NULL,
|
||||
#endif
|
||||
@ -1993,7 +1995,7 @@ static void write_to_socket(struct connection *conn) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *mg_get_mime_type(const char *path) {
|
||||
const char *mg_get_mime_type(struct mg_server *server, const char *path) {
|
||||
const char *ext;
|
||||
size_t i, path_len;
|
||||
|
||||
@ -2007,7 +2009,7 @@ const char *mg_get_mime_type(const char *path) {
|
||||
}
|
||||
}
|
||||
|
||||
return "text/plain";
|
||||
return server->config_options[DEFAULT_MIME_TYPE];
|
||||
}
|
||||
|
||||
static struct uri_handler *find_uri_handler(struct mg_server *server,
|
||||
@ -2093,7 +2095,7 @@ static void get_mime_type(const struct mg_server *server, const char *path,
|
||||
}
|
||||
}
|
||||
|
||||
vec->ptr = mg_get_mime_type(path);
|
||||
vec->ptr = mg_get_mime_type((struct mg_server *)server, path);
|
||||
vec->len = strlen(vec->ptr);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ int mg_printf(struct mg_connection *conn, const char *fmt, ...);
|
||||
|
||||
|
||||
const char *mg_get_header(const struct mg_connection *, const char *name);
|
||||
const char *mg_get_mime_type(const char *file_name);
|
||||
const char *mg_get_mime_type(struct mg_server*, const char *file_name);
|
||||
int mg_get_var(const struct mg_connection *conn, const char *var_name,
|
||||
char *buf, size_t buf_len);
|
||||
int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);
|
||||
|
Loading…
x
Reference in New Issue
Block a user