Skip to content
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

PartEvent API should support limiting the number of file parts #31343

Closed
kzander91 opened this issue Sep 30, 2023 · 5 comments
Closed

PartEvent API should support limiting the number of file parts #31343

kzander91 opened this issue Sep 30, 2023 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@kzander91
Copy link
Contributor

With the "old" WebFlux multipart functionality, we could limit the number of parts with org.springframework.http.codec.multipart.DefaultPartHttpMessageReader#maxParts, and the maximum part size with a combination of org.springframework.http.codec.multipart.DefaultPartHttpMessageReader#maxInMemorySize and org.springframework.http.codec.multipart.DefaultPartHttpMessageReader#maxDiskUsagePerPart.

But org.springframework.http.codec.multipart.PartEventHttpMessageReader does not offer such a configuration. It does have maxInMemorySize, but that can only be used to limit the size of form parts and has no effect on file parts.

Is there a particular reason for not offering that configuration? Is there another recommended way of implementing these limits myself when using PartEvent?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 30, 2023
@poutsma poutsma added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Oct 24, 2023
@poutsma poutsma self-assigned this Oct 24, 2023
@poutsma poutsma removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 24, 2023
@poutsma poutsma added this to the 6.1.0-RC2 milestone Oct 25, 2023
@poutsma
Copy link
Contributor

poutsma commented Oct 25, 2023

We can introduce the maxParts property in the PartEventHttpMessageReader, and will do so for 6.1.

Because the PartEventHttpMessageReader never stores the part contents on disk, it does not make sense to introduce the maxDiskUsagePerPart. The maxInMemorySize property also does not apply, because PartEvent do not contain collated data (unlike Part objects), i.e. the maximum size a PartEvent can have is equal to the HTTP server buffer size. So unless you use buffer, or similar methods, to collate the part events into a list, you should be fine.

@poutsma poutsma changed the title PartEvent API should support limiting the number and maximum size of file parts PartEvent API should support limiting the number of file parts Oct 25, 2023
@kzander91
Copy link
Contributor Author

I have a business requirement that files should be less than 5MB in size and I was using maxDiskUsagePerPart and maxInMemorySize to enforce that. This is now no longer possible...

@poutsma
Copy link
Contributor

poutsma commented Oct 25, 2023

I'll see if I can add a maxPartSize property as well.

@kzander91
Copy link
Contributor Author

kzander91 commented Nov 4, 2023

@poutsma Shouldn't this line

int maxSize = (int) Math.min(this.maxInMemorySize, this.maxPartSize);

take into account that maxPartSize is -1 by default? Otherwise, not setting the new maxPartSize property will effectively disable the existing maxInMemorySize of 256k...

Maybe a better approach would be to rename the properties to something like maxFormPartSize and maxFilePartSize and then only apply them when decoding form parts and file parts respectively...

What do you think?

Context: I'm currently preparing a PR to add auto-configuration for these new properties to Spring Boot and am having trouble coming up with a concise description of what these are actually controlling.

@poutsma
Copy link
Contributor

poutsma commented Nov 6, 2023

@poutsma Shouldn't this line

int maxSize = (int) Math.min(this.maxInMemorySize, this.maxPartSize);

take into account that maxPartSize is -1 by default? Otherwise, not setting the new maxPartSize property effectively disables the existing maxInMemorySize of 256k...

Good point, I will fix that.

Maybe a better approach would be to rename the properties to something like maxFormPartSize and maxFilePartSize and then only apply them when decoding form parts and file parts respectively...

Renaming the properties would break backward compatibility, so that's not really an option at this point. Moreover, this change would ignore the fact that maxInMemorySize is also used to determine the threshold when switching from in-memory to file storage in the DefaultPartHttpMessageReader, and I'd like to keep the properties similar to facilitate switching between the two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants