moremind commented on code in PR #3792:
URL: https://github.com/apache/shenyu/pull/3792#discussion_r936239565
##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java:
##########
@@ -47,20 +49,27 @@ public class WebClientPlugin extends
AbstractHttpClientPlugin<ClientResponse> {
public WebClientPlugin(final WebClient webClient) {
this.webClient = webClient;
}
-
+
@Override
protected Mono<ClientResponse> doRequest(final ServerWebExchange exchange,
final String httpMethod, final URI uri,
final HttpHeaders httpHeaders,
final Flux<DataBuffer> body) {
// springWebflux5.3 mark #exchange() deprecated. because #echange
maybe make memory leak.
// https://github.com/spring-projects/spring-framework/issues/25751
// exchange is deprecated, so change to {@link
WebClient.RequestHeadersSpec#exchangeToMono(Function)}
- // exchangeToMono has two important bug:
- // 1.exchangeToMono can cause NPE when response body is null
- // 2.download file with exchangeToMono can't open
return webClient.method(HttpMethod.valueOf(httpMethod)).uri(uri)
.headers(headers -> headers.addAll(httpHeaders))
.body(BodyInserters.fromDataBuffers(body))
- .exchange()
+ .exchangeToMono(response -> response.bodyToMono(byte[].class)
+ .flatMap(bytes ->
Mono.just(Optional.ofNullable(bytes))).defaultIfEmpty(Optional.empty())
Review Comment:
maybe use Mono.fromCallable()
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]