Browse Source

Expose HttpRequest from ClientResponse

Closes gh-28397
pull/29430/head
rstoyanchev 1 year ago
parent
commit
4a10fa67a5
  1. 6
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java
  2. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java
  3. 18
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/ClientResponseWrapper.java

6
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java

@ -72,6 +72,12 @@ public interface ClientResponse { @@ -72,6 +72,12 @@ public interface ClientResponse {
*/
ExchangeStrategies strategies();
/**
* Return the request associated with the response.
* @since 6.1
*/
HttpRequest request();
/**
* Extract the body with the given {@code BodyExtractor}.
* @param extractor the {@code BodyExtractor} that reads from the response

4
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java

@ -262,8 +262,8 @@ class DefaultClientResponse implements ClientResponse { @@ -262,8 +262,8 @@ class DefaultClientResponse implements ClientResponse {
return this.logPrefix;
}
// Used by DefaultClientResponseBuilder
HttpRequest request() {
@Override
public HttpRequest request() {
return this.requestSupplier.get();
}

18
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/ClientResponseWrapper.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@ -25,6 +25,7 @@ import reactor.core.publisher.Mono; @@ -25,6 +25,7 @@ import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseCookie;
@ -68,11 +69,6 @@ public class ClientResponseWrapper implements ClientResponse { @@ -68,11 +69,6 @@ public class ClientResponseWrapper implements ClientResponse {
return this.delegate;
}
@Override
public ExchangeStrategies strategies() {
return this.delegate.strategies();
}
@Override
public HttpStatusCode statusCode() {
return this.delegate.statusCode();
@ -88,6 +84,16 @@ public class ClientResponseWrapper implements ClientResponse { @@ -88,6 +84,16 @@ public class ClientResponseWrapper implements ClientResponse {
return this.delegate.cookies();
}
@Override
public ExchangeStrategies strategies() {
return this.delegate.strategies();
}
@Override
public HttpRequest request() {
return this.delegate.request();
}
@Override
public <T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor) {
return this.delegate.body(extractor);

Loading…
Cancel
Save