Polishing contribution

Closes gh-30092
This commit is contained in:
rstoyanchev
2023-03-14 11:10:02 +00:00
parent cd8955fa72
commit c3ce847871
2 changed files with 31 additions and 60 deletions

View File

@@ -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.
@@ -370,12 +370,28 @@ class DefaultWebTestClient implements WebTestClient {
private ClientRequest.Builder initRequestBuilder() {
ClientRequest.Builder builder = ClientRequest.create(this.httpMethod, initUri())
.headers(this::initHeaders)
.cookies(this::initCookies)
.headers(headersToUse -> {
if (!CollectionUtils.isEmpty(defaultHeaders)) {
headersToUse.putAll(defaultHeaders);
}
if (!CollectionUtils.isEmpty(this.headers)) {
headersToUse.putAll(this.headers);
}
})
.cookies(cookiesToUse -> {
if (!CollectionUtils.isEmpty(defaultCookies)) {
cookiesToUse.putAll(defaultCookies);
}
if (!CollectionUtils.isEmpty(this.cookies)) {
cookiesToUse.putAll(this.cookies);
}
})
.attributes(attributes -> attributes.putAll(this.attributes));
if (this.httpRequestConsumer != null) {
builder.httpRequest(this.httpRequestConsumer);
}
return builder;
}
@@ -383,23 +399,6 @@ class DefaultWebTestClient implements WebTestClient {
return (this.uri != null ? this.uri : uriBuilderFactory.expand(""));
}
private void initHeaders(HttpHeaders out) {
if (!CollectionUtils.isEmpty(defaultHeaders)) {
out.putAll(defaultHeaders);
}
if (!CollectionUtils.isEmpty(this.headers)) {
out.putAll(this.headers);
}
}
private void initCookies(MultiValueMap<String, String> out) {
if (!CollectionUtils.isEmpty(defaultCookies)) {
out.putAll(defaultCookies);
}
if (!CollectionUtils.isEmpty(this.cookies)) {
out.putAll(this.cookies);
}
}
}