Static: handled unknown MIME types when MIME-filtering active.

This commit is contained in:
Oisin Canty
2021-05-26 16:48:11 +00:00
parent 81e31872e3
commit d67a0c8711
3 changed files with 17 additions and 21 deletions

View File

@@ -1220,7 +1220,7 @@ nxt_conf_vldt_mtypes_extension(nxt_conf_validation_t *vldt,
dup_type = nxt_http_static_mtypes_hash_find(&ctx->hash, &ext); dup_type = nxt_http_static_mtypes_hash_find(&ctx->hash, &ext);
if (dup_type != NULL) { if (dup_type->length != 0) {
return nxt_conf_vldt_error(vldt, "The \"%V\" file extension has been " return nxt_conf_vldt_error(vldt, "The \"%V\" file extension has been "
"declared for \"%V\" and \"%V\" " "declared for \"%V\" and \"%V\" "
"MIME types at the same time.", "MIME types at the same time.",

View File

@@ -84,18 +84,13 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
mtype = nxt_http_static_mtypes_hash_find(&rtcf->mtypes_hash, mtype = nxt_http_static_mtypes_hash_find(&rtcf->mtypes_hash,
&extension); &extension);
if (mtype != NULL) {
ret = nxt_http_route_test_rule(r, action->u.share.types, ret = nxt_http_route_test_rule(r, action->u.share.types,
mtype->start, mtype->length); mtype->start, mtype->length);
if (ret == 1) {
goto mime_ok;
}
if (nxt_slow_path(ret == NXT_ERROR)) { if (nxt_slow_path(ret == NXT_ERROR)) {
goto fail; goto fail;
} }
}
if (ret == 0) {
if (action->u.share.fallback != NULL) { if (action->u.share.fallback != NULL) {
return action->u.share.fallback; return action->u.share.fallback;
} }
@@ -103,8 +98,7 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_request_error(task, r, NXT_HTTP_FORBIDDEN); nxt_http_request_error(task, r, NXT_HTTP_FORBIDDEN);
return NULL; return NULL;
} }
}
mime_ok:
length = action->name.length + r->path->length + index.length; length = action->name.length + r->path->length + index.length;
@@ -298,7 +292,7 @@ mime_ok:
&extension); &extension);
} }
if (mtype != NULL) { if (mtype->length != 0) {
field = nxt_list_zero_add(r->resp.fields); field = nxt_list_zero_add(r->resp.fields);
if (nxt_slow_path(field == NULL)) { if (nxt_slow_path(field == NULL)) {
goto fail; goto fail;
@@ -711,6 +705,8 @@ nxt_http_static_mtypes_hash_find(nxt_lvlhsh_t *hash, nxt_str_t *extension)
nxt_lvlhsh_query_t lhq; nxt_lvlhsh_query_t lhq;
nxt_http_static_mtype_t *mtype; nxt_http_static_mtype_t *mtype;
static nxt_str_t empty = nxt_string("");
lhq.key = *extension; lhq.key = *extension;
lhq.key_hash = nxt_djb_hash_lowcase(lhq.key.start, lhq.key.length); lhq.key_hash = nxt_djb_hash_lowcase(lhq.key.start, lhq.key.length);
lhq.proto = &nxt_http_static_mtypes_hash_proto; lhq.proto = &nxt_http_static_mtypes_hash_proto;
@@ -720,7 +716,7 @@ nxt_http_static_mtypes_hash_find(nxt_lvlhsh_t *hash, nxt_str_t *extension)
return mtype->type; return mtype->type;
} }
return NULL; return ∅
} }

View File

@@ -128,7 +128,7 @@ class TestShareTypes(TestApplicationProto):
{ {
"action": { "action": {
"share": temp_dir + "/assets", "share": temp_dir + "/assets",
"types": ["!application/php"], "types": ["!application/x-httpd-php"],
"fallback": {"proxy": "http://127.0.0.1:7081"}, "fallback": {"proxy": "http://127.0.0.1:7081"},
} }
}, },