Skip to content

Update TestRestTemplate's default cookie handling to match RestTemplate's#49261

Open
apoorvdarshan wants to merge 1 commit intospring-projects:mainfrom
apoorvdarshan:fix/testresttemplate-default-cookie-handling
Open

Update TestRestTemplate's default cookie handling to match RestTemplate's#49261
apoorvdarshan wants to merge 1 commit intospring-projects:mainfrom
apoorvdarshan:fix/testresttemplate-default-cookie-handling

Conversation

@apoorvdarshan
Copy link

@apoorvdarshan apoorvdarshan commented Feb 18, 2026

Summary

  • TestRestTemplate previously disabled cookies by default (StandardCookieSpec.IGNORE), differing from RestTemplate which uses the HTTP client library's default
  • Aligns the defaults so TestRestTemplate no longer explicitly ignores cookies
  • Adds withCookies(HttpCookies) method for explicit cookie control, following the same pattern as withRedirects(HttpRedirects) from Align TestRestTemplate default redirect settings to be the same as RestTemplate #43431
  • Introduces HttpCookies enum, HttpComponentsCookieSpec adapter, and cookies() on RestTemplateBuilder
  • Deprecates HttpClientOption.ENABLE_COOKIES

Fixes gh-48607

Test plan

  • TestRestTemplateTests — verifies default cookie spec is now null (library default), withCookies(ENABLE) returns "strict", withCookies(DISABLE) returns "ignoreCookies"
  • HttpClientSettingsTests — verifies withCookies() and updated orElse() with cookies field
  • HttpClientAutoConfigurationTests — verifies settings construction with new record shape
  • Existing redirect tests remain green

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 18, 2026
@apoorvdarshan apoorvdarshan force-pushed the fix/testresttemplate-default-cookie-handling branch from dff9449 to 7e42613 Compare February 19, 2026 06:24
Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @apoorvdarshan. In addition to the two comments I've made, I think some changes to the various other …HttpClientBuilder classes are missing. The required changes will be similar to the changes that you've made for HttpComponentsHttpClientBuilder to honour the cookies configuration.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Feb 25, 2026
@apoorvdarshan apoorvdarshan force-pushed the fix/testresttemplate-default-cookie-handling branch from 7e42613 to 1a8c7ba Compare February 25, 2026 15:39
Copy link
Author

@apoorvdarshan apoorvdarshan left a comment

Choose a reason for hiding this comment

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

Thanks for the review feedback @wilkinsona! Both items addressed:

  1. Updated the ENABLE_COOKIES deprecation to "for removal in 4.3.0"
  2. Added an explicit deprecated four-argument HttpClientSettings constructor that delegates to the new five-argument canonical constructor to preserve backward compatibility

@wilkinsona
Copy link
Member

wilkinsona commented Feb 25, 2026

Thanks. Did you see this additional comment?

I think some changes to the various other …HttpClientBuilder classes are missing. The required changes will be similar to the changes that you've made for HttpComponentsHttpClientBuilder to honour the cookies configuration.

…te's

Signed-off-by: Apoorv Darshan <ad13dtu@gmail.com>
@apoorvdarshan apoorvdarshan force-pushed the fix/testresttemplate-default-cookie-handling branch from 1a8c7ba to 56c5733 Compare February 25, 2026 15:59
@apoorvdarshan
Copy link
Author

Thanks for pointing that out! I've added cookie handling to the other builders:

  • JdkHttpClientBuilder: Maps HttpCookies to a CookieHandlerENABLE/ENABLE_WHEN_POSSIBLE sets a CookieManager, DISABLE leaves the default (no cookie handler)
  • JettyHttpClientBuilder: Maps HttpCookies to a HttpCookieStoreDISABLE sets HttpCookieStore.Empty, ENABLE/ENABLE_WHEN_POSSIBLE keeps the library default (cookies enabled)

Reactor Netty's HttpClient doesn't have automatic cookie management at the transport level, so no changes were made there.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update TestRestTemplate's default cookie handling to be the same as RestTemplate's

3 participants