mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Follow up changes in Servlet multipart support
Apply similar changes to the Servlet multipart message converter. See gh-37264
This commit is contained in:
+13
-1
@@ -488,6 +488,7 @@ final class MultipartParser {
|
||||
// iterate over buffers in reverse order
|
||||
DataBufferUtils.release(boundaryBuffer);
|
||||
DataBuffer prev;
|
||||
boolean found = false;
|
||||
while ((prev = this.queue.pollLast()) != null) {
|
||||
int prevByteCount = prev.readableByteCount();
|
||||
int prevLen = prevByteCount + len;
|
||||
@@ -497,6 +498,7 @@ final class MultipartParser {
|
||||
DataBufferUtils.release(prev);
|
||||
enqueue(body);
|
||||
flush();
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
@@ -505,11 +507,21 @@ final class MultipartParser {
|
||||
len += prevByteCount;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
// all buffered bytes were boundary bytes: the part had an empty body
|
||||
invokeListener(buffer.factory().allocateBuffer(0), true);
|
||||
}
|
||||
}
|
||||
else /* if (len == 0) */ {
|
||||
// buffer starts with complete delimiter, flush out the previous buffers
|
||||
DataBufferUtils.release(boundaryBuffer);
|
||||
flush();
|
||||
if (this.queue.isEmpty()) {
|
||||
// nothing was ever buffered for this part: the part had an empty body
|
||||
invokeListener(buffer.factory().allocateBuffer(0), true);
|
||||
}
|
||||
else {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
changeState(new HeadersState(), buffer);
|
||||
|
||||
+1
@@ -118,6 +118,7 @@ class MultipartParserTests {
|
||||
parse("no-body.multipart", "boundary", listener);
|
||||
|
||||
listener.assertHeader(headers -> assertThat(headers.hasHeaderValues("Part", List.of("1"))).isTrue())
|
||||
.assertBodyChunk("")
|
||||
.assertHeader(headers -> assertThat(headers.hasHeaderValues("Part", List.of("2"))).isTrue())
|
||||
.assertBodyChunk("a")
|
||||
.assertComplete();
|
||||
|
||||
Reference in New Issue
Block a user