Skip to content

Commit 17ff656

Browse files
authored
Merge pull request #3354 from cesanta/closefree
do not serve files when closing
2 parents b3d27a3 + 4e8965c commit 17ff656

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

mongoose.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,10 +2272,10 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
22722272
status, mg_http_status_code_str(status), (int) mime.len, mime.buf,
22732273
etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "",
22742274
range, opts->extra_headers ? opts->extra_headers : "");
2275-
if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0) {
2275+
if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0 || c->is_closing) {
22762276
c->is_resp = 0;
22772277
mg_fs_close(fd);
2278-
} else {
2278+
} else { // start serving static content only if not closing, see #3354
22792279
// Track to-be-sent content length at the end of c->data, aligned
22802280
size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
22812281
sizeof(size_t) * sizeof(size_t)];

src/http.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
#include "http.h"
12
#include "arch.h"
23
#include "base64.h"
34
#include "fmt.h"
4-
#include "http.h"
55
#include "json.h"
66
#include "log.h"
77
#include "net.h"
@@ -648,10 +648,10 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
648648
status, mg_http_status_code_str(status), (int) mime.len, mime.buf,
649649
etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "",
650650
range, opts->extra_headers ? opts->extra_headers : "");
651-
if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0) {
651+
if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0 || c->is_closing) {
652652
c->is_resp = 0;
653653
mg_fs_close(fd);
654-
} else {
654+
} else { // start serving static content only if not closing, see #3354
655655
// Track to-be-sent content length at the end of c->data, aligned
656656
size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
657657
sizeof(size_t) * sizeof(size_t)];

0 commit comments

Comments
 (0)