diff --git a/mongoose.c b/mongoose.c index 22d1d619..c577088f 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2272,10 +2272,10 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm, status, mg_http_status_code_str(status), (int) mime.len, mime.buf, etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "", range, opts->extra_headers ? opts->extra_headers : ""); - if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0) { + if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0 || c->is_closing) { c->is_resp = 0; mg_fs_close(fd); - } else { + } else { // start serving static content only if not closing, see #3354 // Track to-be-sent content length at the end of c->data, aligned size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) / sizeof(size_t) * sizeof(size_t)]; diff --git a/src/http.c b/src/http.c index 0f287e95..c0360dfb 100644 --- a/src/http.c +++ b/src/http.c @@ -1,7 +1,7 @@ +#include "http.h" #include "arch.h" #include "base64.h" #include "fmt.h" -#include "http.h" #include "json.h" #include "log.h" #include "net.h" @@ -648,10 +648,10 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm, status, mg_http_status_code_str(status), (int) mime.len, mime.buf, etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "", range, opts->extra_headers ? opts->extra_headers : ""); - if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0) { + if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0 || c->is_closing) { c->is_resp = 0; mg_fs_close(fd); - } else { + } else { // start serving static content only if not closing, see #3354 // Track to-be-sent content length at the end of c->data, aligned size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) / sizeof(size_t) * sizeof(size_t)];