Skip to content

degroff/0.3.5.maintenance file manager #35

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

Merged
merged 14 commits into from
Jul 7, 2025

Conversation

robotdan
Copy link
Member

Summary

Add in additional control for multipart streams.

Reviewer notes

This is on a maintenance branch. The plan will be to either merge this change into main or possibly just rebuild something very similar on main depending upon how much of this translates.

@robotdan robotdan changed the base branch from main to 0.3.5.maintenance June 11, 2025 00:52
@robotdan robotdan marked this pull request as ready for review July 3, 2025 18:15
Copy link
Member

@voidmain voidmain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let some comments. Feel free to take and leave whatever you like.

this.temporaryFilenameSuffix = other.temporaryFilenameSuffix;
}

public boolean deleteTemporaryFiles() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break the pattern below of everything being a getter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good point. I could rename to isDeleteTemporaryFiles or getDeleteTemporaryFiles to make it more consistent.

throw new ContentTooLarge(maximumRequestSize, detailedMessage);
}

end += read;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? The condition end == -1 can only happen if the first read is empty right? That would make this like be 0 += -1 and then the if-statement would return false on the next line?

Just want to make sure this block of code will eventually complete even in edge cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct based upon how end is set above. If I condition this with read > 0 the tests hang.
There is a bug in this code though that I see now - I was not looking for read > 0 before calculating bytesRead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

new MultipartStream(inputStream, boundary, getMultipartFileManager(), multipartConfiguration).process(parameters, files);
}

public void setMultipartConfiguration(MultipartConfiguration multipartConfiguration) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of the pattern where this is always clobbered. Why not back the variable here final and then copy things over using the with methods? Or add a copyFrom method to the MultipartConfiguration object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

this.request = new HTTPRequest(configuration.getContextPath(), listener.isTLS() ? "https" : "http", listener.getPort(), ipAddress);

// Create a deep copy of the MultipartConfiguration so that the request may optionally modify the configuration on a per-request basis.
this.request.getMultiPartStreamProcessor().setMultipartConfiguration(new MultipartConfiguration(configuration.getMultipartConfiguration()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in the Configuration object about clobbering objects.

@@ -157,7 +169,7 @@ public ProcessorState read(ByteBuffer buffer) throws IOException {
// If the next state is not preamble, that means we are done processing that and ready to handle the request in a separate thread
if (requestState != RequestState.Preamble && requestState != RequestState.Expect) {
logger.trace("(RWo)");
future = threadPool.submit(new HTTPWorker(configuration.getHandler(), configuration.getLoggerFactory(), this, request, response));
future = threadPool.submit(new HTTPWorker(configuration, configuration.getHandler(), configuration.getLoggerFactory(), this, request, response));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to pass in the configuration, why not remove the other objects and just pull them from the configuration in the constructor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I considered that, happy to make that change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

public void post_server_configuration_file_upload_disabled(String scheme) throws Exception {
// File uploads disabled
withScheme(scheme)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? If files are disabled, should we be returning an error or should we just ignore them and still handle the rest of the request? I can go either way, but seems like you were planning on looking at the action in Prime and disabling files if the action didn't need them, which would blow up if the request has files, which we could just ignore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it just depends on how we wish to handle. I'd rather not ignore them because I assume if a multipart request contains both files and form data they are all required to be complete. But open to other ideas.

@robotdan robotdan merged commit c317411 into 0.3.5.maintenance Jul 7, 2025
@robotdan robotdan deleted the degroff/0.3.5.maintenance-file_manager branch July 7, 2025 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants