changeset 13972:67b8f2ee41ed 13.0

mod_http_file_share: Improve debug logging around unexpected file sizes These didn't have any debug logging and it can be confusing that the "file too large" is also used for a cut-off chunked upload. Not sure if it is worth it to double those checks into > and < just for this.
author Kim Alvefur <zash@zash.se>
date Thu, 02 Oct 2025 21:04:20 +0200
parents b7714c28442f
children 1746a6bd4644 9974b210d620
files plugins/mod_http_file_share.lua
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_http_file_share.lua	Tue Sep 30 16:11:49 2025 +0200
+++ b/plugins/mod_http_file_share.lua	Thu Oct 02 21:04:20 2025 +0200
@@ -66,7 +66,7 @@
 		code = 413;
 		type = "modify";
 		condition = "not-acceptable";
-		text = "File too large";
+		text = "File too large"; -- also used if file is too small
 		extra = {
 			tag = st.stanza("file-too-large", { xmlns = namespace }):tag("max-file-size"):text(tostring(file_size_limit));
 		};
@@ -293,6 +293,7 @@
 			return upload_errors.new("unauthz", { request = request });
 		end
 		if request.headers.content_length and tonumber(request.headers.content_length) ~= authed_upload_info.filesize then
+			module:log("debug", "Unexpected Content-Length %q, expected %s", request.headers.content_length, B(authed_upload_info.filesize));
 			return upload_errors.new("filesize", { request = request });
 			-- Note: We don't know the size if the upload is streamed in chunked encoding,
 			-- so we also check the final file size on completion.
@@ -351,6 +352,7 @@
 		local uploaded, err = errors.coerce(request.body_sink:close());
 		if final_size ~= upload_info.filesize then
 			-- Could be too short as well, but we say the same thing
+			module:log("debug", "Final file size is %s but expected %s (%s difference)", B(final_size), B(upload_info.filesize), B(upload_info.filesize - final_size));
 			uploaded, err = false, upload_errors.new("filesize", { request = request });
 		end
 		if uploaded then