Allow to change URL/method in ClientRequest.Builder
This commit exposes the ClientRequest's URL and HttpMethod fields via a setter, so that they can be changed more easily in a request that was created via ClientRequest.from(ClientRequest). Issue: SPR-16093
This commit is contained in:
@@ -134,6 +134,20 @@ public interface ClientRequest {
|
||||
*/
|
||||
interface Builder {
|
||||
|
||||
/**
|
||||
* Set the method of the request.
|
||||
* @param method the new method
|
||||
* @return this builder
|
||||
*/
|
||||
Builder method(HttpMethod method);
|
||||
|
||||
/**
|
||||
* Set the url of the request.
|
||||
* @param url the new url
|
||||
* @return this builder
|
||||
*/
|
||||
Builder url(URI url);
|
||||
|
||||
/**
|
||||
* Add the given header value(s) under the given name.
|
||||
* @param headerName the header name
|
||||
|
||||
@@ -49,16 +49,16 @@ import org.springframework.web.reactive.function.BodyInserters;
|
||||
*/
|
||||
class DefaultClientRequestBuilder implements ClientRequest.Builder {
|
||||
|
||||
private final HttpMethod method;
|
||||
|
||||
private final URI url;
|
||||
|
||||
private final HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
private final MultiValueMap<String, String> cookies = new LinkedMultiValueMap<>();
|
||||
|
||||
private final Map<String, Object> attributes = new LinkedHashMap<>();
|
||||
|
||||
private HttpMethod method;
|
||||
|
||||
private URI url;
|
||||
|
||||
private BodyInserter<?, ? super ClientHttpRequest> inserter = BodyInserters.empty();
|
||||
|
||||
|
||||
@@ -67,6 +67,19 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientRequest.Builder method(HttpMethod method) {
|
||||
Assert.notNull(method, "'method' must not be null");
|
||||
this.method = method;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientRequest.Builder url(URI url) {
|
||||
Assert.notNull(url, "'url' must not be null");
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientRequest.Builder header(String headerName, String... headerValues) {
|
||||
|
||||
Reference in New Issue
Block a user