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)];
+#include "http.h"
#include "arch.h"
#include "base64.h"
#include "fmt.h"
-#include "http.h"
#include "json.h"
#include "log.h"
#include "net.h"
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)];