Skip to content

Commit 4632985

Browse files
committed
Ensure state of PartGenerator accepts buffers
This commit makes sure that the current state of the PartGenerator is able to handle an incoming buffer, possibly requested because of a request coming from the subscription. All states accept new buffers except the WritingFileState. Closes gh-29227
1 parent 51d109d commit 4632985

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ void requestToken() {
229229
if (upstream() != null &&
230230
!this.sink.isCancelled() &&
231231
this.sink.requestedFromDownstream() > 0 &&
232+
this.state.get().canRequest() &&
232233
this.requestOutstanding.compareAndSet(false, true)) {
233234
request(1);
234235
}
@@ -291,6 +292,13 @@ private interface State {
291292
default void error(Throwable throwable) {
292293
}
293294

295+
/**
296+
* Indicates whether the current state is ready to accept a new token.
297+
*/
298+
default boolean canRequest() {
299+
return true;
300+
}
301+
294302
/**
295303
* Cleans up any state.
296304
*/
@@ -814,6 +822,11 @@ private Mono<Void> writeInternal(DataBuffer dataBuffer) {
814822
}
815823
}
816824

825+
@Override
826+
public boolean canRequest() {
827+
return false;
828+
}
829+
817830
@Override
818831
public void dispose() {
819832
this.disposed = true;

0 commit comments

Comments
 (0)