You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2007/10/06 13:11:10 UTC
svn commit: r582479 - in
/jakarta/httpcomponents/httpclient/trunk/module-client/src:
main/java/org/apache/http/client/protocol/
main/java/org/apache/http/cookie/ main/java/org/apache/http/impl/cookie/
test/java/org/apache/http/impl/cookie/
Author: olegk
Date: Sat Oct 6 04:11:09 2007
New Revision: 582479
URL: http://svn.apache.org/viewvc?rev=582479&view=rev
Log:
* Merged CookieVersionSupport methods into the CookieSpec interface
* Added support for Set-Cookie2 and Cookie2 headers
Removed:
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieVersionSupport.java
Modified:
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/SM.java
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java Sat Oct 6 04:11:09 2007
@@ -167,6 +167,24 @@
}
}
+ int ver = cookieSpec.getVersion();
+ if (ver > 0) {
+ boolean needVersionHeader = false;
+ for (int i = 0; i < cookies.length; i++) {
+ if (ver != cookies[i].getVersion()) {
+ needVersionHeader = true;
+ }
+ }
+
+ if (needVersionHeader) {
+ Header header = cookieSpec.getVersionHeader();
+ if (header != null) {
+ // Advertise cookie version support
+ request.addHeader(header);
+ }
+ }
+ }
+
// Stick the CookieSpec and CookieOrigin instances to the HTTP context
// so they could be obtained by the response interceptor
context.setAttribute(ClientContext.COOKIE_SPEC, cookieSpec);
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java Sat Oct 6 04:11:09 2007
@@ -36,6 +36,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
@@ -95,17 +96,25 @@
LOG.info("CookieOrigin not available in HTTP context");
return;
}
- Header[] headers = response.getHeaders(SM.SET_COOKIE);
- processCookies(headers, cookieSpec, cookieOrigin, cookieStore);
+ HeaderIterator it = response.headerIterator(SM.SET_COOKIE);
+ processCookies(it, cookieSpec, cookieOrigin, cookieStore);
+
+ // see if the cookie spec supports cookie versioning.
+ if (cookieSpec.getVersion() > 0) {
+ // process set-cookie2 headers.
+ // Cookie2 will replace equivalent Cookie instances
+ it = response.headerIterator(SM.SET_COOKIE2);
+ processCookies(it, cookieSpec, cookieOrigin, cookieStore);
+ }
}
private static void processCookies(
- final Header[] headers,
+ final HeaderIterator iterator,
final CookieSpec cookieSpec,
final CookieOrigin cookieOrigin,
final CookieStore cookieStore) {
- for (int i = 0; i < headers.length; i++) {
- Header header = headers[i];
+ while (iterator.hasNext()) {
+ Header header = iterator.nextHeader();
try {
Cookie[] cookies = cookieSpec.parse(header, cookieOrigin);
for (int c = 0; c < cookies.length; c++) {
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java Sat Oct 6 04:11:09 2007
@@ -51,6 +51,14 @@
public interface CookieSpec {
/**
+ * Returns version of the state management this cookie specification
+ * conforms to.
+ *
+ * @return version of the state management specification
+ */
+ int getVersion();
+
+ /**
* Parse the <tt>"Set-Cookie"</tt> Header into an array of Cookies.
*
* <p>This method will not perform the validation of the resultant
@@ -95,4 +103,11 @@
*/
Header[] formatCookies(Cookie[] cookies);
+ /**
+ * Returns a request header identifying what version of the state management
+ * specification is understood. May be <code>null</code> if the cookie
+ * specification does not support <tt>Cookie2</tt> header.
+ */
+ Header getVersionHeader();
+
}
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/SM.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/SM.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/SM.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/SM.java Sat Oct 6 04:11:09 2007
@@ -40,8 +40,9 @@
*/
public interface SM {
- public static final String COOKIE = "Cookie";
- public static final String COOKIE_2 = "Cookie2";
- public static final String SET_COOKIE = "Set-Cookie";
+ public static final String COOKIE = "Cookie";
+ public static final String COOKIE_2 = "Cookie2";
+ public static final String SET_COOKIE = "Set-Cookie";
+ public static final String SET_COOKIE2 = "Set-Cookie2";
}
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java Sat Oct 6 04:11:09 2007
@@ -152,5 +152,13 @@
}
return new Header[] { new BufferedHeader(buffer) };
}
+
+ public int getVersion() {
+ return 0;
+ }
+
+ public Header getVersionHeader() {
+ return null;
+ }
}
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java Sat Oct 6 04:11:09 2007
@@ -134,4 +134,12 @@
return new Header[] { new BufferedHeader(buffer) };
}
+ public int getVersion() {
+ return 0;
+ }
+
+ public Header getVersionHeader() {
+ return null;
+ }
+
}
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java Sat Oct 6 04:11:09 2007
@@ -226,5 +226,13 @@
}
}
}
+
+ public int getVersion() {
+ return 1;
+ }
+
+ public Header getVersionHeader() {
+ return null;
+ }
}
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java Sat Oct 6 04:11:09 2007
@@ -41,7 +41,6 @@
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
-import org.apache.http.cookie.CookieVersionSupport;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SM;
import org.apache.http.message.BufferedHeader;
@@ -55,7 +54,7 @@
*
* @since 3.1
*/
-public class RFC2965Spec extends RFC2109Spec implements CookieVersionSupport {
+public class RFC2965Spec extends RFC2109Spec {
/**
* Default constructor
Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java?rev=582479&r1=582478&r2=582479&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java Sat Oct 6 04:11:09 2007
@@ -77,6 +77,14 @@
public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
}
+ public int getVersion() {
+ return 0;
+ }
+
+ public Header getVersionHeader() {
+ return null;
+ }
+
}
private static class DummyCookieAttribHandler implements CookieAttributeHandler {