From 2207e87c8f532716394999d9556bbbfe6be55a3c Mon Sep 17 00:00:00 2001 From: Sergey Lyubka <sergey.lyubka@cesanta.com> Date: Fri, 11 Dec 2015 08:22:15 +0200 Subject: [PATCH] Fix DAV for non-existent files. Improve logging PUBLISHED_FROM=39a2810ad9bebcf1676b982f7523aa9c2339cc4f --- mongoose.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mongoose.c b/mongoose.c index aa081a367..5bbe42131 100644 --- a/mongoose.c +++ b/mongoose.c @@ -6248,6 +6248,10 @@ static void send_options(struct mg_connection *nc) { nc->flags |= MG_F_SEND_AND_CLOSE; } +static int is_creation_request(const struct http_message *hm) { + return mg_vcmp(&hm->method, "MKCOL") == 0 || mg_vcmp(&hm->method, "PUT") == 0; +} + void mg_send_http_file(struct mg_connection *nc, char *path, size_t path_buf_len, struct http_message *hm, struct mg_serve_http_opts *opts) { @@ -6269,7 +6273,8 @@ void mg_send_http_file(struct mg_connection *nc, char *path, !is_authorized(hm, path, is_directory, opts->auth_domain, opts->per_directory_auth_file, 0)) { mg_send_digest_auth_request(nc, opts->auth_domain); - } else if ((stat_result != 0 || is_file_hidden(path, opts)) && !is_dav) { + } else if ((stat_result != 0 || is_file_hidden(path, opts)) && + !is_creation_request(hm)) { mg_printf(nc, "%s", "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n"); } else if (is_directory && path[strlen(path) - 1] != '/' && !is_dav) { mg_printf(nc, -- GitLab