summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2021-05-04 21:11:03 +0200
committerDenys Vlasenko2021-05-04 21:11:03 +0200
commit1c698178858ac2b332849a2e24283e6060f9b179 (patch)
treea0fd66e60d30a33dfafbf09fa899856aed0cd92b
parent32a8258be78371154dd66b931a9628aad0efd337 (diff)
downloadbusybox-1c698178858ac2b332849a2e24283e6060f9b179.zip
busybox-1c698178858ac2b332849a2e24283e6060f9b179.tar.gz
httpd: avoid one stat() call for "GET /dirname" case
function old new delta handle_incoming_and_exit 2172 2173 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/httpd.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index 958b3c3..fc52faf 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2355,13 +2355,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
tptr++;
}
- /* If URL is a directory, add '/' */
- if (urlp[-1] != '/') {
- if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) {
- found_moved_temporarily = urlcopy;
- }
- }
-
/* Log it */
if (verbose > 1)
bb_error_msg("url:%s", urlcopy);
@@ -2370,6 +2363,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
while ((tptr = strchr(tptr + 1, '/')) != NULL) {
/* have path1/path2 */
*tptr = '\0';
+//TODO: can we avoid is_directory() test here?
if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) {
/* may have subdir config */
parse_conf(urlcopy + 1, SUBDIR_PARSE);
@@ -2401,19 +2395,23 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
strcpy(urlp, index_page);
}
if (stat(tptr, &sb) == 0) {
+ /* If URL is a directory with no slash, set up
+ * "HTTP/1.1 302 Found" "Location: /dir/" reply */
+ if (urlp[-1] != '/' && S_ISDIR(sb.st_mode)) {
+ found_moved_temporarily = urlcopy;
+ } else {
#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
- char *suffix = strrchr(tptr, '.');
- if (suffix) {
- Htaccess *cur;
- for (cur = script_i; cur; cur = cur->next) {
- if (strcmp(cur->before_colon + 1, suffix) == 0) {
- cgi_type = CGI_INTERPRETER;
- break;
+ char *suffix = strrchr(tptr, '.');
+ if (suffix) {
+ Htaccess *cur;
+ for (cur = script_i; cur; cur = cur->next) {
+ if (strcmp(cur->before_colon + 1, suffix) == 0) {
+ cgi_type = CGI_INTERPRETER;
+ break;
+ }
}
}
- }
#endif
- if (!found_moved_temporarily) {
file_size = sb.st_size;
last_mod = sb.st_mtime;
}