Mercurial > prosody-hg
comparison plugins/mod_http_file_share.lua @ 13973:1746a6bd4644
Merge 13.0->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 02 Oct 2025 21:08:15 +0200 |
| parents | fc489086e09a 67b8f2ee41ed |
| children | eae7d0350a52 |
comparison
equal
deleted
inserted
replaced
| 13971:97d15552d364 | 13973:1746a6bd4644 |
|---|---|
| 66 filetype = { type = "modify"; condition = "not-acceptable"; text = "File type not allowed" }; | 66 filetype = { type = "modify"; condition = "not-acceptable"; text = "File type not allowed" }; |
| 67 filesize = { | 67 filesize = { |
| 68 code = 413; | 68 code = 413; |
| 69 type = "modify"; | 69 type = "modify"; |
| 70 condition = "not-acceptable"; | 70 condition = "not-acceptable"; |
| 71 text = "File too large"; | 71 text = "File too large"; -- also used if file is too small |
| 72 extra = { | 72 extra = { |
| 73 tag = st.stanza("file-too-large", { xmlns = namespace }):tag("max-file-size"):text(tostring(file_size_limit)); | 73 tag = st.stanza("file-too-large", { xmlns = namespace }):tag("max-file-size"):text(tostring(file_size_limit)); |
| 74 }; | 74 }; |
| 75 }; | 75 }; |
| 76 filesizefmt = { type = "modify"; condition = "bad-request"; text = "File size must be positive integer"; }; | 76 filesizefmt = { type = "modify"; condition = "bad-request"; text = "File size must be positive integer"; }; |
| 293 if not path or authed_upload_info.slot ~= path:match("^[^/]+") then | 293 if not path or authed_upload_info.slot ~= path:match("^[^/]+") then |
| 294 module:log("debug", "Invalid upload slot: %q, path: %q", authed_upload_info.slot, path); | 294 module:log("debug", "Invalid upload slot: %q, path: %q", authed_upload_info.slot, path); |
| 295 return upload_errors.new("unauthz", { request = request }); | 295 return upload_errors.new("unauthz", { request = request }); |
| 296 end | 296 end |
| 297 if request.headers.content_length and tonumber(request.headers.content_length) ~= authed_upload_info.filesize then | 297 if request.headers.content_length and tonumber(request.headers.content_length) ~= authed_upload_info.filesize then |
| 298 module:log("debug", "Unexpected Content-Length %q, expected %s", request.headers.content_length, B(authed_upload_info.filesize)); | |
| 298 return upload_errors.new("filesize", { request = request }); | 299 return upload_errors.new("filesize", { request = request }); |
| 299 -- Note: We don't know the size if the upload is streamed in chunked encoding, | 300 -- Note: We don't know the size if the upload is streamed in chunked encoding, |
| 300 -- so we also check the final file size on completion. | 301 -- so we also check the final file size on completion. |
| 301 end | 302 end |
| 302 upload_info = authed_upload_info; | 303 upload_info = authed_upload_info; |
| 351 if request.body_sink then | 352 if request.body_sink then |
| 352 local final_size = request.body_sink:seek(); | 353 local final_size = request.body_sink:seek(); |
| 353 local uploaded, err = errors.coerce(request.body_sink:close()); | 354 local uploaded, err = errors.coerce(request.body_sink:close()); |
| 354 if final_size ~= upload_info.filesize then | 355 if final_size ~= upload_info.filesize then |
| 355 -- Could be too short as well, but we say the same thing | 356 -- Could be too short as well, but we say the same thing |
| 357 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)); | |
| 356 uploaded, err = false, upload_errors.new("filesize", { request = request }); | 358 uploaded, err = false, upload_errors.new("filesize", { request = request }); |
| 357 end | 359 end |
| 358 if uploaded then | 360 if uploaded then |
| 359 module:log("debug", "Upload of %q completed, %s", filename, B(final_size)); | 361 module:log("debug", "Upload of %q completed, %s", filename, B(final_size)); |
| 360 assert(os.rename(filename.."~", filename)); | 362 assert(os.rename(filename.."~", filename)); |
