It was already indicated in #24819.
It can be either handled as separate test (as suggested in issue) or it is possible to add multiple cookies to existing retrieve test.
24819 was declined with reasoning that
assertThat(request.getHeaders().toMultimap().get(HttpHeaders.COOKIE))
.isEqualTo(Arrays.asList("testkey=testvalue", "testkey2=testvalue2"));
returns all cookies.
But in https://tools.ietf.org/html/rfc6265#section-5.4 RFC clearly states that
When the user agent generates an HTTP request, the user agent MUST NOT attach more than one Cookie header field.
WebClient using reactor netty attaches each cookie as separate cookie header which obviously not complies with RFC even though it passes the test if all cookie headers are joined
Comment From: kkondratov
We've recently ran into the same issue where using the WebClient.RequestBodySpec#cookies
method that accepts a MultiValueMap multiple cookies were set in the request.
running
final var cookies = new LinkedMultiValueMap<String, String>();
cookies.add("cookie1", "foo");
cookies.add("cookie2", "bar");
final var spec = webClient.metho(GET).uri(url)
.cookies(specCookies -> specCookies.addAll(cookies));
resulted in an HTTP request where two cookies were set:
WRITE: ....B GET /ru HTTP/1.1
...
cookie: cookie1=foo
cookie: cookie2=bar
EDIT: spring webflux version 5.3.18
Comment From: incedo
Any ideas if this will be treated as bug?
Comment From: sdeleuze
Looks like I can reproduce with Spring Boot 3.2.0 via https://github.com/sdeleuze/demo-webclient-cookies.
With ReactorClientHttpConnector
I see:
+--------+-------------------------------------------------+----------------+
|00000000| 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a |GET / HTTP/1.1..|
|00000010| 61 63 63 65 70 74 2d 65 6e 63 6f 64 69 6e 67 3a |accept-encoding:|
|00000020| 20 67 7a 69 70 0d 0a 75 73 65 72 2d 61 67 65 6e | gzip..user-agen|
|00000030| 74 3a 20 52 65 61 63 74 6f 72 4e 65 74 74 79 2f |t: ReactorNetty/|
|00000040| 31 2e 31 2e 31 33 0d 0a 68 6f 73 74 3a 20 6c 6f |1.1.13..host: lo|
|00000050| 63 61 6c 68 6f 73 74 3a 38 30 38 30 0d 0a 61 63 |calhost:8080..ac|
|00000060| 63 65 70 74 3a 20 2a 2f 2a 0d 0a 63 6f 6f 6b 69 |cept: */*..cooki|
|00000070| 65 3a 20 63 6f 6f 6b 69 65 31 3d 66 6f 6f 0d 0a |e: cookie1=foo..|
|00000080| 63 6f 6f 6b 69 65 3a 20 63 6f 6f 6b 69 65 32 3d |cookie: cookie2=|
|00000090| 62 61 72 0d 0a 0d 0a |bar.... |
+--------+-------------------------------------------------+----------------+
With JdkClientHttpConnector
I see:
+--------+-------------------------------------------------+----------------+
|00000000| 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a |GET / HTTP/1.1..|
|00000010| 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 55 70 67 72 |Connection: Upgr|
|00000020| 61 64 65 2c 20 48 54 54 50 32 2d 53 65 74 74 69 |ade, HTTP2-Setti|
|00000030| 6e 67 73 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e |ngs..Content-Len|
|00000040| 67 74 68 3a 20 30 0d 0a 48 6f 73 74 3a 20 6c 6f |gth: 0..Host: lo|
|00000050| 63 61 6c 68 6f 73 74 3a 38 30 38 30 0d 0a 48 54 |calhost:8080..HT|
|00000060| 54 50 32 2d 53 65 74 74 69 6e 67 73 3a 20 41 41 |TP2-Settings: AA|
|00000070| 45 41 41 45 41 41 41 41 49 41 41 41 41 42 41 41 |EAAEAAAAIAAAABAA|
|00000080| 4d 41 41 41 42 6b 41 41 51 42 41 41 41 41 41 41 |MAAABkAAQBAAAAAA|
|00000090| 55 41 41 45 41 41 0d 0a 55 70 67 72 61 64 65 3a |UAAEAA..Upgrade:|
|000000a0| 20 68 32 63 0d 0a 55 73 65 72 2d 41 67 65 6e 74 | h2c..User-Agent|
|000000b0| 3a 20 4a 61 76 61 2d 68 74 74 70 2d 63 6c 69 65 |: Java-http-clie|
|000000c0| 6e 74 2f 31 37 2e 30 2e 37 0d 0a 41 63 63 65 70 |nt/17.0.7..Accep|
|000000d0| 74 3a 20 2a 2f 2a 0d 0a 43 6f 6f 6b 69 65 3a 20 |t: */*..Cookie: |
|000000e0| 63 6f 6f 6b 69 65 31 3d 66 6f 6f 3b 63 6f 6f 6b |cookie1=foo;cook|
|000000f0| 69 65 32 3d 62 61 72 0d 0a 0d 0a |ie2=bar.... |
+--------+-------------------------------------------------+----------------+
@violetagg Looks like something that should be fixed on Reactor Netty side to me, so I would suggest to close this issue and create one in https://github.com/reactor/reactor-netty if there is not an existing one. Do you agree?
Comment From: violetagg
Yeah please open an issue in https://github.com/reactor/reactor-netty Ultimately you need a fix for Spring 5.x or just Spring 6.x ?
Comment From: sdeleuze
We would need a fix for both Spring Framework 5.3.x and 6.x. I have created https://github.com/reactor/reactor-netty/issues/2983. Thanks!