Skip to content

Commit d34584b

Browse files
committed
Merge pull request #947 from izeye
* gh-947: Use single Cookie header in HttpRequestSnippet Closes gh-947
2 parents 1dcd748 + 5d9b7ec commit d34584b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ private List<Map<String, String>> getHeaders(OperationRequest request) {
103103
}
104104
}
105105

106+
List<String> cookies = new ArrayList<>();
106107
for (RequestCookie cookie : request.getCookies()) {
107-
headers.add(header(HttpHeaders.COOKIE, String.format("%s=%s", cookie.getName(), cookie.getValue())));
108+
cookies.add(String.format("%s=%s", cookie.getName(), cookie.getValue()));
109+
}
110+
if (!cookies.isEmpty()) {
111+
headers.add(header(HttpHeaders.COOKIE, String.join("; ", cookies)));
108112
}
109113

110114
if (requiresFormEncodingContentTypeHeader(request)) {

spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ public void getRequestWithCookies() throws IOException {
8282
.build());
8383
assertThat(this.generatedSnippets.httpRequest())
8484
.is(httpRequest(RequestMethod.GET, "/foo").header(HttpHeaders.HOST, "localhost")
85-
.header(HttpHeaders.COOKIE, "name1=value1")
86-
.header(HttpHeaders.COOKIE, "name2=value2"));
85+
.header(HttpHeaders.COOKIE, "name1=value1; name2=value2"));
8786
}
8887

8988
@Test

0 commit comments

Comments
 (0)