From 338e3e9686cda28a9540e81a49b0133122ce184a Mon Sep 17 00:00:00 2001 From: shado23 Date: Sat, 29 Apr 2023 16:43:53 +0200 Subject: [PATCH] Support X-Sendfile in response to a POST request It's supported in NGINX and Apache and can be useful in certain cases, e.g. a submitted form that results in a static file being delivered. --- ext/iodine/http.c | 2 ++ ext/iodine/http_internal.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ext/iodine/http.c b/ext/iodine/http.c index abbee0b..3711502 100644 --- a/ext/iodine/http.c +++ b/ext/iodine/http.c @@ -564,6 +564,8 @@ int http_sendfile2(http_s *h, const char *prefix, size_t prefix_len, http_set_header(h, HTTP_HEADER_CONTENT_LENGTH, fiobj_num_new(length)); http_finish(h); return 0; + } else if (!strncasecmp("post", s.data, 4)) { + goto open_file; } break; } diff --git a/ext/iodine/http_internal.c b/ext/iodine/http_internal.c index fc56c48..5fab78e 100644 --- a/ext/iodine/http_internal.c +++ b/ext/iodine/http_internal.c @@ -42,7 +42,8 @@ void http_on_request_handler______internal(http_s *h, fiobj_hash_get2(h->headers, fiobj_obj2hash(HTTP_HEADER_ACCEPT)), HTTP_HVALUE_SSE_MIME)) goto eventsource; - if (settings->public_folder) { + if (settings->public_folder && + (fiobj_obj2cstr(h->method).len != 4 || strncasecmp("post", fiobj_obj2cstr(h->method).data, 4))) { fio_str_info_s path_str = fiobj_obj2cstr(h->path); if (!http_sendfile2(h, settings->public_folder, settings->public_folder_length, path_str.data,