Skip to content

Commit

Permalink
Add ClientRequest attribute for URI template
Browse files Browse the repository at this point in the history
Issue: SPR-16537
  • Loading branch information
rstoyanchev committed Mar 1, 2018
1 parent 36cfdf6 commit 9352e3d
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
*/
class DefaultWebClient implements WebClient {

private static final String URI_TEMPLATE_ATTRIBUTE = WebClient.class.getName() + ".uriTemplate";

private static final Mono<ClientResponse> NO_HTTP_CLIENT_RESPONSE_ERROR = Mono.error(
new IllegalStateException("The underlying HTTP client completed without emitting a response."));

Expand Down Expand Up @@ -161,20 +163,22 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec {
@Nullable
private BodyInserter<?, ? super ClientHttpRequest> inserter;

@Nullable
private Map<String, Object> attributes;
private final Map<String, Object> attributes = new LinkedHashMap<>(4);


DefaultRequestBodyUriSpec(HttpMethod httpMethod) {
this.httpMethod = httpMethod;
}

@Override
public RequestBodySpec uri(String uriTemplate, Object... uriVariables) {
attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate);
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));
}

@Override
public RequestBodySpec uri(String uriTemplate, Map<String, ?> uriVariables) {
attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate);
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));
}

Expand Down Expand Up @@ -203,13 +207,6 @@ private MultiValueMap<String, String> getCookies() {
return this.cookies;
}

private Map<String, Object> getAttributes() {
if (this.attributes == null) {
this.attributes = new LinkedHashMap<>(4);
}
return this.attributes;
}

@Override
public DefaultRequestBodyUriSpec header(String headerName, String... headerValues) {
for (String headerValue : headerValues) {
Expand All @@ -227,14 +224,14 @@ public DefaultRequestBodyUriSpec headers(Consumer<HttpHeaders> headersConsumer)

@Override
public RequestBodySpec attribute(String name, Object value) {
getAttributes().put(name, value);
this.attributes.put(name, value);
return this;
}

@Override
public RequestBodySpec attributes(Consumer<Map<String, Object>> attributesConsumer) {
Assert.notNull(attributesConsumer, "'attributesConsumer' must not be null");
attributesConsumer.accept(getAttributes());
attributesConsumer.accept(this.attributes);
return this;
}

Expand Down Expand Up @@ -330,7 +327,7 @@ private ClientRequest.Builder initRequestBuilder() {
return ClientRequest.method(this.httpMethod, uri)
.headers(headers -> headers.addAll(initHeaders()))
.cookies(cookies -> cookies.addAll(initCookies()))
.attributes(attributes -> attributes.putAll(getAttributes()));
.attributes(attributes -> attributes.putAll(this.attributes));
}

private HttpHeaders initHeaders() {
Expand Down

0 comments on commit 9352e3d

Please sign in to comment.