diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-05-04 21:11:03 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-05-04 21:11:03 +0200 |
commit | 1c698178858ac2b332849a2e24283e6060f9b179 (patch) | |
tree | a0fd66e60d30a33dfafbf09fa899856aed0cd92b | |
parent | 32a8258be78371154dd66b931a9628aad0efd337 (diff) | |
download | busybox-w32-1c698178858ac2b332849a2e24283e6060f9b179.tar.gz busybox-w32-1c698178858ac2b332849a2e24283e6060f9b179.tar.bz2 busybox-w32-1c698178858ac2b332849a2e24283e6060f9b179.zip |
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.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 958b3c300..fc52fafea 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -2355,13 +2355,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2355 | tptr++; | 2355 | tptr++; |
2356 | } | 2356 | } |
2357 | 2357 | ||
2358 | /* If URL is a directory, add '/' */ | ||
2359 | if (urlp[-1] != '/') { | ||
2360 | if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) { | ||
2361 | found_moved_temporarily = urlcopy; | ||
2362 | } | ||
2363 | } | ||
2364 | |||
2365 | /* Log it */ | 2358 | /* Log it */ |
2366 | if (verbose > 1) | 2359 | if (verbose > 1) |
2367 | bb_error_msg("url:%s", urlcopy); | 2360 | bb_error_msg("url:%s", urlcopy); |
@@ -2370,6 +2363,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2370 | while ((tptr = strchr(tptr + 1, '/')) != NULL) { | 2363 | while ((tptr = strchr(tptr + 1, '/')) != NULL) { |
2371 | /* have path1/path2 */ | 2364 | /* have path1/path2 */ |
2372 | *tptr = '\0'; | 2365 | *tptr = '\0'; |
2366 | //TODO: can we avoid is_directory() test here? | ||
2373 | if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) { | 2367 | if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) { |
2374 | /* may have subdir config */ | 2368 | /* may have subdir config */ |
2375 | parse_conf(urlcopy + 1, SUBDIR_PARSE); | 2369 | parse_conf(urlcopy + 1, SUBDIR_PARSE); |
@@ -2401,19 +2395,23 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2401 | strcpy(urlp, index_page); | 2395 | strcpy(urlp, index_page); |
2402 | } | 2396 | } |
2403 | if (stat(tptr, &sb) == 0) { | 2397 | if (stat(tptr, &sb) == 0) { |
2398 | /* If URL is a directory with no slash, set up | ||
2399 | * "HTTP/1.1 302 Found" "Location: /dir/" reply */ | ||
2400 | if (urlp[-1] != '/' && S_ISDIR(sb.st_mode)) { | ||
2401 | found_moved_temporarily = urlcopy; | ||
2402 | } else { | ||
2404 | #if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR | 2403 | #if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR |
2405 | char *suffix = strrchr(tptr, '.'); | 2404 | char *suffix = strrchr(tptr, '.'); |
2406 | if (suffix) { | 2405 | if (suffix) { |
2407 | Htaccess *cur; | 2406 | Htaccess *cur; |
2408 | for (cur = script_i; cur; cur = cur->next) { | 2407 | for (cur = script_i; cur; cur = cur->next) { |
2409 | if (strcmp(cur->before_colon + 1, suffix) == 0) { | 2408 | if (strcmp(cur->before_colon + 1, suffix) == 0) { |
2410 | cgi_type = CGI_INTERPRETER; | 2409 | cgi_type = CGI_INTERPRETER; |
2411 | break; | 2410 | break; |
2411 | } | ||
2412 | } | 2412 | } |
2413 | } | 2413 | } |
2414 | } | ||
2415 | #endif | 2414 | #endif |
2416 | if (!found_moved_temporarily) { | ||
2417 | file_size = sb.st_size; | 2415 | file_size = sb.st_size; |
2418 | last_mod = sb.st_mtime; | 2416 | last_mod = sb.st_mtime; |
2419 | } | 2417 | } |