Skip to content

Commit

Permalink
MultipartParser should take into account read position
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Sep 11, 2023
1 parent 5c7bf0c commit 8f9de72
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public void onNext(DataBuffer buffer) {
if (logger.isTraceEnabled()) {
logger.trace("Boundary found @" + endIdx + " in " + buffer);
}
int len = endIdx - this.boundaryLength + 1;
int len = endIdx - this.boundaryLength + 1 - boundaryBuffer.readPosition();
if (len > 0) {
// whole boundary in buffer.
// slice off the body part, and flush
Expand All @@ -538,10 +538,11 @@ else if (len < 0) {
DataBufferUtils.release(boundaryBuffer);
DataBuffer prev;
while ((prev = this.queue.pollLast()) != null) {
int prevLen = prev.readableByteCount() + len;
int prevByteCount = prev.readableByteCount();
int prevLen = prevByteCount + len;
if (prevLen > 0) {
// slice body part of previous buffer, and flush it
DataBuffer body = prev.split(prevLen);
DataBuffer body = prev.split(prevLen + prev.readPosition());
DataBufferUtils.release(prev);
enqueue(body);
flush();
Expand All @@ -550,7 +551,7 @@ else if (len < 0) {
else {
// previous buffer only contains boundary bytes
DataBufferUtils.release(prev);
len += prev.readableByteCount();
len += prevByteCount;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorNetty2HttpServer;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -69,9 +68,6 @@ class MultipartRouterFunctionIntegrationTests extends AbstractRouterFunctionInte

@ParameterizedHttpServerTest
void multipartData(HttpServer httpServer) throws Exception {
// TODO Determine why Reactor Netty 2 fails: https://github.com/spring-projects/spring-framework/issues/31110
assumeFalse(httpServer instanceof ReactorNetty2HttpServer, "Potential bug in Netty 5 multipart support");

startServer(httpServer);

Mono<ResponseEntity<Void>> result = webClient
Expand All @@ -90,9 +86,6 @@ void multipartData(HttpServer httpServer) throws Exception {

@ParameterizedHttpServerTest
void parts(HttpServer httpServer) throws Exception {
// TODO Determine why Reactor Netty 2 fails: https://github.com/spring-projects/spring-framework/issues/31110
assumeFalse(httpServer instanceof ReactorNetty2HttpServer, "Potential bug in Netty 5 multipart support");

startServer(httpServer);

Mono<ResponseEntity<Void>> result = webClient
Expand All @@ -113,9 +106,6 @@ void parts(HttpServer httpServer) throws Exception {
void transferTo(HttpServer httpServer) throws Exception {
// TODO Determine why Undertow fails: https://github.com/spring-projects/spring-framework/issues/25310
assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow currently fails with transferTo");
// TODO Determine why Reactor Netty 2 fails: https://github.com/spring-projects/spring-framework/issues/31110
assumeFalse(httpServer instanceof ReactorNetty2HttpServer, "Potential bug in Netty 5 multipart support");

verifyTransferTo(httpServer);
}

Expand Down Expand Up @@ -154,9 +144,6 @@ private void verifyTransferTo(HttpServer httpServer) throws Exception {

@ParameterizedHttpServerTest
void partData(HttpServer httpServer) throws Exception {
// TODO Determine why Reactor Netty 2 fails: https://github.com/spring-projects/spring-framework/issues/31110
assumeFalse(httpServer instanceof ReactorNetty2HttpServer, "Potential bug in Netty 5 multipart support");

startServer(httpServer);

Mono<ResponseEntity<Void>> result = webClient
Expand All @@ -176,9 +163,6 @@ void partData(HttpServer httpServer) throws Exception {
@ParameterizedHttpServerTest
void proxy(HttpServer httpServer) throws Exception {
assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow currently fails proxying requests");
// TODO Determine why Reactor Netty 2 fails: https://github.com/spring-projects/spring-framework/issues/31110
assumeFalse(httpServer instanceof ReactorNetty2HttpServer, "Potential bug in Netty 5 multipart support");

startServer(httpServer);

Mono<ResponseEntity<Void>> result = webClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.AbstractHttpHandlerIntegrationTests;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorNetty2HttpServer;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -88,9 +87,6 @@ protected void startServer(HttpServer httpServer) throws Exception {

@ParameterizedHttpServerTest
void requestPart(HttpServer httpServer) throws Exception {
// TODO Determine why Reactor Netty 2 fails: https://github.com/spring-projects/spring-framework/issues/31110
assumeFalse(httpServer instanceof ReactorNetty2HttpServer, "Potential bug in Netty 5 multipart support");

startServer(httpServer);

Mono<ResponseEntity<Void>> result = webClient
Expand Down Expand Up @@ -174,9 +170,6 @@ void filePartsMono(HttpServer httpServer) throws Exception {
void transferTo(HttpServer httpServer) throws Exception {
// TODO Determine why Undertow fails: https://github.com/spring-projects/spring-framework/issues/25310
assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow currently fails with transferTo");
// TODO Determine why Reactor Netty 2 fails: https://github.com/spring-projects/spring-framework/issues/31110
assumeFalse(httpServer instanceof ReactorNetty2HttpServer, "Potential bug in Netty 5 multipart support");

startServer(httpServer);

Flux<String> result = webClient
Expand All @@ -195,9 +188,6 @@ void transferTo(HttpServer httpServer) throws Exception {

@ParameterizedHttpServerTest
void modelAttribute(HttpServer httpServer) throws Exception {
// TODO Determine why Reactor Netty 2 fails: https://github.com/spring-projects/spring-framework/issues/31110
assumeFalse(httpServer instanceof ReactorNetty2HttpServer, "Potential bug in Netty 5 multipart support");

startServer(httpServer);

Mono<String> result = webClient
Expand Down

0 comments on commit 8f9de72

Please sign in to comment.