Browse Source

Replace ReadCancellationException with takeWhile

Closes gh-24125
pull/24137/head
Rossen Stoyanchev 6 years ago
parent
commit
3a48682226
  1. 19
      spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java

19
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -264,18 +264,11 @@ public abstract class BodyExtractors { @@ -264,18 +264,11 @@ public abstract class BodyExtractors {
() -> consumeAndCancel(message).then(Mono.empty()) : Mono::empty;
}
private static Mono<Void> consumeAndCancel(ReactiveHttpInputMessage message) {
return message.getBody()
.map(buffer -> {
DataBufferUtils.release(buffer);
throw new ReadCancellationException();
})
.onErrorResume(ReadCancellationException.class, ex -> Mono.empty())
.then();
}
@SuppressWarnings("serial")
private static class ReadCancellationException extends RuntimeException {
private static Flux<DataBuffer> consumeAndCancel(ReactiveHttpInputMessage message) {
return message.getBody().takeWhile(buffer -> {
DataBufferUtils.release(buffer);
return false;
});
}
}

Loading…
Cancel
Save