mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-08 16:11:18 +00:00
Merge pull request #3354 from cesanta/closefree
do not serve files when closing
This commit is contained in:
2 files changed
+5
-5
No files matched your search
+2
-2
@@ -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,
|
status, mg_http_status_code_str(status), (int) mime.len, mime.buf,
|
||||||
etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "",
|
etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "",
|
||||||
range, opts->extra_headers ? opts->extra_headers : "");
|
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;
|
c->is_resp = 0;
|
||||||
mg_fs_close(fd);
|
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
|
// 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)) /
|
size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
|
||||||
sizeof(size_t) * sizeof(size_t)];
|
sizeof(size_t) * sizeof(size_t)];
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
|
#include "http.h"
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "http.h"
|
|
||||||
#include "json.h"
|
#include "json.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "net.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,
|
status, mg_http_status_code_str(status), (int) mime.len, mime.buf,
|
||||||
etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "",
|
etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "",
|
||||||
range, opts->extra_headers ? opts->extra_headers : "");
|
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;
|
c->is_resp = 0;
|
||||||
mg_fs_close(fd);
|
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
|
// 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)) /
|
size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
|
||||||
sizeof(size_t) * sizeof(size_t)];
|
sizeof(size_t) * sizeof(size_t)];
|
||||||
|
|||||||
Reference in new issue
Block a user