Skip to content

Commit 5d9b7ec

Browse files
izeyewilkinsona
authored andcommitted
Use single Cookie header in HttpRequestSnippet
See https://www.rfc-editor.org/rfc/rfc6265#section-5.4 See gh-947
1 parent 1dcd748 commit 5d9b7ec

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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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)