comparison plugins/mod_http_file_share.lua @ 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 0b01f40df0f9
children 1746a6bd4644 9974b210d620
comparison
equal deleted inserted replaced
13965:b7714c28442f 13972:67b8f2ee41ed
64 filetype = { type = "modify"; condition = "not-acceptable"; text = "File type not allowed" }; 64 filetype = { type = "modify"; condition = "not-acceptable"; text = "File type not allowed" };
65 filesize = { 65 filesize = {
66 code = 413; 66 code = 413;
67 type = "modify"; 67 type = "modify";
68 condition = "not-acceptable"; 68 condition = "not-acceptable";
69 text = "File too large"; 69 text = "File too large"; -- also used if file is too small
70 extra = { 70 extra = {
71 tag = st.stanza("file-too-large", { xmlns = namespace }):tag("max-file-size"):text(tostring(file_size_limit)); 71 tag = st.stanza("file-too-large", { xmlns = namespace }):tag("max-file-size"):text(tostring(file_size_limit));
72 }; 72 };
73 }; 73 };
74 filesizefmt = { type = "modify"; condition = "bad-request"; text = "File size must be positive integer"; }; 74 filesizefmt = { type = "modify"; condition = "bad-request"; text = "File size must be positive integer"; };
291 if not path or authed_upload_info.slot ~= path:match("^[^/]+") then 291 if not path or authed_upload_info.slot ~= path:match("^[^/]+") then
292 module:log("debug", "Invalid upload slot: %q, path: %q", authed_upload_info.slot, path); 292 module:log("debug", "Invalid upload slot: %q, path: %q", authed_upload_info.slot, path);
293 return upload_errors.new("unauthz", { request = request }); 293 return upload_errors.new("unauthz", { request = request });
294 end 294 end
295 if request.headers.content_length and tonumber(request.headers.content_length) ~= authed_upload_info.filesize then 295 if request.headers.content_length and tonumber(request.headers.content_length) ~= authed_upload_info.filesize then
296 module:log("debug", "Unexpected Content-Length %q, expected %s", request.headers.content_length, B(authed_upload_info.filesize));
296 return upload_errors.new("filesize", { request = request }); 297 return upload_errors.new("filesize", { request = request });
297 -- Note: We don't know the size if the upload is streamed in chunked encoding, 298 -- Note: We don't know the size if the upload is streamed in chunked encoding,
298 -- so we also check the final file size on completion. 299 -- so we also check the final file size on completion.
299 end 300 end
300 upload_info = authed_upload_info; 301 upload_info = authed_upload_info;
349 if request.body_sink then 350 if request.body_sink then
350 local final_size = request.body_sink:seek(); 351 local final_size = request.body_sink:seek();
351 local uploaded, err = errors.coerce(request.body_sink:close()); 352 local uploaded, err = errors.coerce(request.body_sink:close());
352 if final_size ~= upload_info.filesize then 353 if final_size ~= upload_info.filesize then
353 -- Could be too short as well, but we say the same thing 354 -- Could be too short as well, but we say the same thing
355 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));
354 uploaded, err = false, upload_errors.new("filesize", { request = request }); 356 uploaded, err = false, upload_errors.new("filesize", { request = request });
355 end 357 end
356 if uploaded then 358 if uploaded then
357 module:log("debug", "Upload of %q completed, %s", filename, B(final_size)); 359 module:log("debug", "Upload of %q completed, %s", filename, B(final_size));
358 assert(os.rename(filename.."~", filename)); 360 assert(os.rename(filename.."~", filename));