mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-28 20:58:31 +00:00
Optimise file serving path
This commit is contained in:
1 parent
cddff2b1b8
commit
fb4fae9174
2 files changed
+10
-10
No files matched your search
+5
-5
@@ -1275,17 +1275,18 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
mg_http_reply(c, 404, "", "Invalid URI [%.*s]\n", (int) hm->uri.len,
|
mg_http_reply(c, 404, "", "Invalid URI [%.*s]\n", (int) hm->uri.len,
|
||||||
hm->uri.ptr);
|
hm->uri.ptr);
|
||||||
} else {
|
} else {
|
||||||
FILE *fp = fopen(t2, "r");
|
struct stat st;
|
||||||
|
int res = stat(t2, &st);
|
||||||
#if MG_ENABLE_SSI
|
#if MG_ENABLE_SSI
|
||||||
if (is_index && fp == NULL) {
|
if (is_index && res != 0) {
|
||||||
char *p = t2 + strlen(t2);
|
char *p = t2 + strlen(t2);
|
||||||
while (p > t2 && p[-1] != '/') p--;
|
while (p > t2 && p[-1] != '/') p--;
|
||||||
strncpy(p, "index.shtml", (size_t)(&t2[sizeof(t2)] - p - 2));
|
strncpy(p, "index.shtml", (size_t)(&t2[sizeof(t2)] - p - 2));
|
||||||
t2[sizeof(t2) - 1] = '\0';
|
t2[sizeof(t2) - 1] = '\0';
|
||||||
fp = fopen(t2, "r");
|
res = stat(t2, &st);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (is_index && fp == NULL) {
|
if (is_index && res != 0) {
|
||||||
#if MG_ENABLE_DIRECTORY_LISTING
|
#if MG_ENABLE_DIRECTORY_LISTING
|
||||||
listdir(c, hm, opts, t2);
|
listdir(c, hm, opts, t2);
|
||||||
#else
|
#else
|
||||||
@@ -1302,7 +1303,6 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
mg_http_serve_file(c, hm, t2, guess_content_type(t2),
|
mg_http_serve_file(c, hm, t2, guess_content_type(t2),
|
||||||
opts->extra_headers);
|
opts->extra_headers);
|
||||||
}
|
}
|
||||||
if (fp != NULL) fclose(fp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -856,17 +856,18 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
mg_http_reply(c, 404, "", "Invalid URI [%.*s]\n", (int) hm->uri.len,
|
mg_http_reply(c, 404, "", "Invalid URI [%.*s]\n", (int) hm->uri.len,
|
||||||
hm->uri.ptr);
|
hm->uri.ptr);
|
||||||
} else {
|
} else {
|
||||||
FILE *fp = fopen(t2, "r");
|
struct stat st;
|
||||||
|
int res = stat(t2, &st);
|
||||||
#if MG_ENABLE_SSI
|
#if MG_ENABLE_SSI
|
||||||
if (is_index && fp == NULL) {
|
if (is_index && res != 0) {
|
||||||
char *p = t2 + strlen(t2);
|
char *p = t2 + strlen(t2);
|
||||||
while (p > t2 && p[-1] != '/') p--;
|
while (p > t2 && p[-1] != '/') p--;
|
||||||
strncpy(p, "index.shtml", (size_t)(&t2[sizeof(t2)] - p - 2));
|
strncpy(p, "index.shtml", (size_t)(&t2[sizeof(t2)] - p - 2));
|
||||||
t2[sizeof(t2) - 1] = '\0';
|
t2[sizeof(t2) - 1] = '\0';
|
||||||
fp = fopen(t2, "r");
|
res = stat(t2, &st);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (is_index && fp == NULL) {
|
if (is_index && res != 0) {
|
||||||
#if MG_ENABLE_DIRECTORY_LISTING
|
#if MG_ENABLE_DIRECTORY_LISTING
|
||||||
listdir(c, hm, opts, t2);
|
listdir(c, hm, opts, t2);
|
||||||
#else
|
#else
|
||||||
@@ -883,7 +884,6 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
mg_http_serve_file(c, hm, t2, guess_content_type(t2),
|
mg_http_serve_file(c, hm, t2, guess_content_type(t2),
|
||||||
opts->extra_headers);
|
opts->extra_headers);
|
||||||
}
|
}
|
||||||
if (fp != NULL) fclose(fp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user