Skip to content

Conversation

@Jarvx
Copy link

@Jarvx Jarvx commented Oct 21, 2025

Issue: #11819

Bug description

Calling MutableHttpRequest.cookie(s) is expected to keep a single Cookie header updated. However, multiple Cookie headers are created depending on the request implementation.

Root cause & Fix

To fix this with minimal changes, update SimpleHttpRequest.updateCookies() so that it:

  • Removes any existing Cookie header(s),
  • Encodes each cookie using ClientCookieEncoder.INSTANCE (consistent with other implementations),
  • Joins encoded cookie strings into a single header value using "; " as separator when there are multiple cookies,
  • Writes that single header via headers.set(HttpHeaders.COOKIE, headerValue).

This preserves insertion order via SimpleCookies.getAll() iteration, supports last-writer-wins because SimpleCookies.put replaces by name, and ensures a single header value is maintained for cookies.

Steps to reproduce

Please use this command to see the output from provided test:

./gradlew :test-suite-kotlin-ksp:test

Jarvx added 2 commits October 21, 2025 20:16
…roducing multiple Cookie header values when cookies were added one-by-one (while other implementations like the Netty client already behaved).
@Jarvx Jarvx changed the title Fix 11819 Fix 11819: updating SimpleHttpRequest.updateCookies to remove existing cookie headers Oct 21, 2025
@Jarvx
Copy link
Author

Jarvx commented Oct 24, 2025

I'll close this pr first because the CI fails.

@Jarvx Jarvx closed this Oct 24, 2025

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CookieHeaderSingleValueTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test should be placed in where other cookie related tests are keep in the io.micronaut.http.cookie package of the micronaut-http module

Copy link
Author

@Jarvx Jarvx Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I'll move it to the folder http/src/test/ . Please understand that it's not easy to find perfect test case for me at the moment. I'll need your feedback for this information.

@Jarvx Jarvx reopened this Oct 24, 2025
@Jarvx Jarvx changed the title Fix 11819: updating SimpleHttpRequest.updateCookies to remove existing cookie headers [GenAI] Fix 11819: updating SimpleHttpRequest.updateCookies to remove existing cookie headers Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants