From 2b69ac0ae9efb29e0867e9ce32e786dc6da35aa0 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 8 Jul 2009 19:10:52 +0000 Subject: [PATCH] HttpClient will no longer send expired cookies back to the origin server git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@792269 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 3 +++ .../http/client/protocol/RequestAddCookies.java | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 5c0f4b71f..5b6bd9a97 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,6 +1,9 @@ Changes since 4.0 beta 2 ------------------- +* HttpClient will no longer send expired cookies back to the origin server. + Contributed by Oleg Kalnichevski + * [HTTPCLIENT-856] Proxy NTLM authentication no longer fails on a redirect to a different host. Contributed by Oleg Kalnichevski diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java b/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java index dae34fec5..935df0096 100644 --- a/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java +++ b/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Date; import java.util.List; import net.jcip.annotations.Immutable; @@ -173,12 +174,19 @@ public class RequestAddCookies implements HttpRequestInterceptor { List cookies = new ArrayList(cookieStore.getCookies()); // Find cookies matching the given origin List matchedCookies = new ArrayList(); + Date now = new Date(); for (Cookie cookie : cookies) { - if (cookieSpec.match(cookie, cookieOrigin)) { - if (this.log.isDebugEnabled()) { - this.log.debug("Cookie " + cookie + " match " + cookieOrigin); + if (cookie.getExpiryDate() == null || cookie.getExpiryDate().after(now)) { + if (cookieSpec.match(cookie, cookieOrigin)) { + if (this.log.isDebugEnabled()) { + this.log.debug("Cookie " + cookie + " match " + cookieOrigin); + } + matchedCookies.add(cookie); + } + } else { + if (this.log.isDebugEnabled()) { + this.log.debug("Cookie " + cookie + " expired"); } - matchedCookies.add(cookie); } } // Generate Cookie request headers