summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2019-05-12 03:27:55 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2019-05-13 20:27:49 -0400
commit8ae06467481273ab912d92aa083109b31b18d1b7 (patch)
treecb06ff6280171b759a0ad64b82f5f302c51b47d9
parentd9e2dd4b2efcae4a373ce5d4e11d550ca33d8a5b (diff)
downloadlighttpd1.4-8ae06467481273ab912d92aa083109b31b18d1b7.tar.gz
lighttpd1.4-8ae06467481273ab912d92aa083109b31b18d1b7.zip
[core] chunkqueue perf: skip opening 0-length file
-rw-r--r--src/http-header-glue.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/http-header-glue.c b/src/http-header-glue.c
index 31af16cf..08cc03cb 100644
--- a/src/http-header-glue.c
+++ b/src/http-header-glue.c
@@ -473,8 +473,10 @@ void http_response_send_file (server *srv, connection *con, buffer *path) {
/*(Note: O_NOFOLLOW affects only the final path segment,
* the target file, not any intermediate symlinks along path)*/
- const int fd = fdevent_open_cloexec(path->ptr, con->conf.follow_symlink, O_RDONLY, 0);
- if (fd < 0) {
+ const int fd = (0 != sce->st.st_size)
+ ? fdevent_open_cloexec(path->ptr, con->conf.follow_symlink, O_RDONLY, 0)
+ : -1;
+ if (fd < 0 && 0 != sce->st.st_size) {
con->http_status = (errno == ENOENT) ? 404 : 403;
if (con->conf.log_request_handling) {
log_error_write(srv, __FILE__, __LINE__, "sbs", "file open failed:", path, strerror(errno));
@@ -524,11 +526,17 @@ void http_response_send_file (server *srv, connection *con, buffer *path) {
}
if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) {
- close(fd);
+ if (fd >= 0) close(fd);
return;
}
}
+ if (fd < 0) { /* 0-length file */
+ con->http_status = 200;
+ con->file_finished = 1;
+ return;
+ }
+
if (con->conf.range_requests
&& (200 == con->http_status || 0 == con->http_status)
&& NULL != (vb = http_header_request_get(con, HTTP_HEADER_RANGE, CONST_STR_LEN("Range")))