WebClient handles no Content-Type with data correctly
Issue: SPR-17482
This commit is contained in:
parent
e4c84ec757
commit
a5339d71ea
|
@ -224,16 +224,15 @@ public abstract class BodyExtractors {
|
|||
|
||||
Flux<T> result;
|
||||
if (message.getHeaders().getContentType() == null) {
|
||||
// Maybe it's okay, if there is no content..
|
||||
result = message.getBody().map(o -> {
|
||||
// Maybe it's okay there is no content type, if there is no content..
|
||||
result = message.getBody().map(buffer -> {
|
||||
DataBufferUtils.release(buffer);
|
||||
throw ex;
|
||||
});
|
||||
}
|
||||
else {
|
||||
result = Flux.error(ex);
|
||||
}
|
||||
if (message instanceof ClientHttpResponse) {
|
||||
result = consumeAndCancel(message).thenMany(result);
|
||||
result = message instanceof ClientHttpResponse ?
|
||||
consumeAndCancel(message).thenMany(Flux.error(ex)) : Flux.error(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package org.springframework.web.reactive.function.client;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
|
@ -28,12 +29,14 @@ import org.junit.Test;
|
|||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
|
||||
import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.ReactorResourceFactory;
|
||||
import org.springframework.web.reactive.function.UnsupportedMediaTypeException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -103,6 +106,21 @@ public class WebClientDataBufferAllocatingTests extends AbstractDataBufferAlloca
|
|||
assertEquals(1, this.server.getRequestCount());
|
||||
}
|
||||
|
||||
@Test // SPR-17482
|
||||
public void bodyToMonoVoidWithoutContentType() {
|
||||
|
||||
this.server.enqueue(new MockResponse()
|
||||
.setResponseCode(HttpStatus.ACCEPTED.value())
|
||||
.setChunkedBody("{\"foo\" : \"123\", \"baz\" : \"456\", \"baz\" : \"456\"}", 5));
|
||||
|
||||
Mono<Map<String, String>> mono = this.webClient.get()
|
||||
.uri("/sample").accept(MediaType.APPLICATION_JSON)
|
||||
.retrieve()
|
||||
.bodyToMono(new ParameterizedTypeReference<Map<String, String>>() {});
|
||||
|
||||
StepVerifier.create(mono).expectError(UnsupportedMediaTypeException.class).verify(Duration.ofSeconds(3));
|
||||
assertEquals(1, this.server.getRequestCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStatusWithBodyNotConsumed() {
|
||||
|
|
Loading…
Reference in New Issue