Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

MatveiMiroshnichenko
Copy link

Proposed changes

These changes will partially fix #838. Without calling ngx_http_dav_error, there is no chance for a 507 status code to be returned. Instead, a 500 status code is being returned when there is no more space left on the device.

It is important to note that these changes will only work properly when temporary data is being written to a separate partition/disk. When the storage is full and there is a PUT request on DAV, the core part of nginx will successfully write a temporary file, and afterwards the WebDAV PUT handler will fail to rename it, returning 507 as expected. In cases where temporary data and the target location are on the same disk/partition, this fix will NOT work because nginx will fail to write the temporary file (which is handled by the core part of nginx, as far as I can see).

Also, as a disclaimer: I am not proficient with C, I am just using nginx, found this problem, and tried to find a workaround that will not break everything. That is the reason I am not proposing a complete fix. Sorry, I don't know how to fix it completely and properly. Nevertheless, I think this PR could still be useful.

Copy link
Contributor

@pluknet pluknet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could change ngx_http_read_client_request_body() error handling as well
(cc @arut) by mapping the internal error to a specific one based on ngx_errno.
Please test if it works for you.
NGX_HTTP_CONFLICT was chosen instead to match what we do for MKCOL (and on a common sense).

I still don't know how to usefully propose patches on GH interface, so it goes inline.

diff --git a/src/http/modules/ngx_http_dav_module.c b/src/http/modules/ngx_http_dav_module.c
index cfb98929e..cdebf5ffa 100644
--- a/src/http/modules/ngx_http_dav_module.c
+++ b/src/http/modules/ngx_http_dav_module.c
@@ -175,6 +175,11 @@ ngx_http_dav_handler(ngx_http_request_t *r)
 
         rc = ngx_http_read_client_request_body(r, ngx_http_dav_put_handler);
 
+        if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
+            return ngx_http_dav_error(NULL, ngx_errno, NGX_HTTP_CONFLICT,
+                                      NULL, NULL);
+        }
+
         if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
             return rc;
         }
@@ -207,6 +212,7 @@ ngx_http_dav_put_handler(ngx_http_request_t *r)
 {
     size_t                    root;
     time_t                    date;
+    ngx_int_t                 rc;
     ngx_str_t                *temp, path;
     ngx_uint_t                status;
     ngx_file_info_t           fi;
@@ -280,7 +286,8 @@ ngx_http_dav_put_handler(ngx_http_request_t *r)
     }
 
     if (ngx_ext_rename_file(temp, &path, &ext) != NGX_OK) {
-        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+        rc = ngx_http_dav_error(NULL, ngx_errno, NGX_HTTP_CONFLICT, NULL, NULL);
+        ngx_http_finalize_request(r, rc);
         return;
     }
 
@@ -1063,7 +1070,9 @@ ngx_http_dav_error(ngx_log_t *log, ngx_err_t err, ngx_int_t not_found,
         rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
-    ngx_log_error(level, log, err, "%s \"%s\" failed", failed, path);
+    if (log) {
+        ngx_log_error(level, log, err, "%s \"%s\" failed", failed, path);
+    }
 
     return rc;
 }

@MatveiMiroshnichenko
Copy link
Author

I can confirm that this patch works as expected and im able to receive 507. Should I apply it to this pull request?

@pluknet
Copy link
Contributor

pluknet commented Sep 18, 2025

I can confirm that this patch works as expected and im able to receive 507. Should I apply it to this pull request?

That would be nice, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebDAV module - 507 Insufficient storage status code is not being returned on PUT
2 participants