-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect behavior of per-request limits #496
Incorrect behavior of per-request limits #496
Comments
+1 |
Thanks for reporting! Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that. (Alternatively a PR with a proposed change would also be fine). |
@mcollina, I think I found the problem. |
The limits are enforced when the file is consumed (when the data is read from the underlying socket). |
Prerequisites
Fastify version
4.24.3
Plugin version
8.0.0
Node.js version
21.2.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
W11. 23H2 (22631.2715)
Description
Clear and concise:
I also want to clarify that I am using TypeScript.
TypeScript version: 5.3.2.
Steps to Reproduce
From plugin types:
In
BusboyConfig
interface simply nothrowFileSizeLimit
.Set limits for
request.files()
Set
throwFileSizeLimit: true
globallySend larger files and in larger quantities. As a result, we do NOT get exception.
However, If you specify the same parameters globally or for the
saveRequestFiles
function, the limits will work correctly.Expected Behavior
The first thing I would like to say is that the instructions in the documentation are incorrect (or am I wrong?).
Example from docs:
However, I cannot specify such a parameter due to differences in types.
files()
allowBusboyConfig
interface, in which there is nothrowFileSizeLimit
parameter. It is only available in theFastifyMultipartBaseOptions
interface.What I'm trying to do: set basic global limits when registering a plugin and specify the limits of each route separately, for part of them, as an overwrite of the global ones.
Global:
For route (I can't set
throwFileSizeLimit
because of the problem described earlier):await request.files({ limits: { files: 1, fileSize: 1 } });
The limits specified globally work correctly, but the specified limits for a request are completely ignored.
I tried this way: use
saveRequestFiles(opts)
, where setting limits works correctly, however, I cannot gettoBuffer()
from thesavedRequestFiles
array, which makes this function not relevant for me.The text was updated successfully, but these errors were encountered: