NIFI-15888 Add size limit to Standard Content Viewer#11303
Conversation
| response.setStatus(HttpServletResponse.SC_OK); | ||
| } | ||
| } else { | ||
| contentStream.transferTo(response.getOutputStream()); |
There was a problem hiding this comment.
For content larger than the response buffer, the response commits during transferTo, so does the later setStatus(SC_PARTIAL_CONTENT) actually reach the client, or does it silently return 200 with truncated content?
There was a problem hiding this comment.
Good catch, the test behavior masked this important detail. I adjusted the approach to get the expected Content Length from the source, and used that to get and set the response status prior to handling the stream.
| final LimitedStandardContentViewerController limitedController = new LimitedStandardContentViewerController(); | ||
| limitedController.doGet(request, response); | ||
|
|
||
| verify(response).setStatus(eq(HttpServletResponse.SC_PARTIAL_CONTENT)); |
There was a problem hiding this comment.
Since MockServletOutputStream never commits the response, does this test really verify that a real container would send 206 after the body is written?
There was a problem hiding this comment.
Thanks for pointing this out, I reworked the implementation to set the response status earlier.
|
Thanks for the review @pvillard31, good catch on the order of setting the response status. I made some adjustments to get the source content length and pass it to the The |
pvillard31
left a comment
There was a problem hiding this comment.
Thanks @exceptionfactory - latest LGTM
Summary
NIFI-15888 Adds an internal size limit of 10 MB to the Standard Content Viewer, avoiding attempts to load, format, and render large FlowFiles.
The internal limit of 10 MB aligns with a previous comment on Apache Avro formatting, which actually limited to the output size to 2 MB.
The implementation uses the
LimitingInputStreamto avoid reading more than 10 MB from the referenced FlowFile. The limit applies to both formatted and unformatted responses. Unformatted responses with content exceeding the limit return anHTTP 206status indicating Partial Content returned. Formatted may throw an exception when the limit does not align with expected structural boundaries. In this case, the server returns an HTTP 500 with message indicating length exceeds maximum. As a best effort viewer, returning an error avoids both server and client memory consumption concerns. The hexadecimal viewer continues to provide a general way to view initial bytes.Additional unit tests exercise length limiting behavior with formatted and unformatted responses.
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000VerifiedstatusPull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
./mvnw clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation