Index: src/java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.186 diff -u -r1.186 HttpMethodBase.java --- src/java/org/apache/commons/httpclient/HttpMethodBase.java 22 Oct 2003 19:31:00 -0000 1.186 +++ src/java/org/apache/commons/httpclient/HttpMethodBase.java 28 Oct 2003 02:44:58 -0000 @@ -1465,7 +1465,8 @@ *
* This implementation will handle the Set-Cookie and
* Set-Cookie2 headers, if any, adding the relevant cookies to
- * the given {@link HttpState}.
+ * the given {@link HttpState}. Cookie parsing can be toggled using the
+ * COOKIE_PARSING_ENABLED configuration parameter.
*
Set-Cookie or Set-Cookie2 response headers, adding
+ * the relevant cookies to the given {@link HttpState state}.
+ *
+ * @param conn the requests connection
+ * @param state the state for storing the parsed cookies
+ */
+ private void processResponseCookieHeaders(HttpConnection conn, HttpState state) {
+
Header[] headers = getResponseHeaderGroup().getHeaders("set-cookie2");
//Only process old style set-cookie headers if new style headres
//are not present
@@ -1530,7 +1548,7 @@
}
}
}
-
+
/**
* This method is invoked immediately after
* {@link #readStatusLine(HttpState,HttpConnection)} and can be overridden by
Index: src/java/org/apache/commons/httpclient/params/HttpMethodParams.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java,v
retrieving revision 1.5
diff -u -r1.5 HttpMethodParams.java
--- src/java/org/apache/commons/httpclient/params/HttpMethodParams.java 22 Oct 2003 19:31:00 -0000 1.5
+++ src/java/org/apache/commons/httpclient/params/HttpMethodParams.java 28 Oct 2003 02:44:59 -0000
@@ -179,6 +179,14 @@
public static final String USE_EXPECT_CONTINUE = "http.protocol.expect-continue";
/**
+ * Enables/disables cookie parsing. When enabled, cookies will be parsed using the {@link
+ * #COOKIE_POLICY configured cookie policy}. When disabled, all cookies will be rejected.
+ *
+ * This parameter expects a value of type {@link Boolean}
+ */ + public static final String COOKIE_PARSING_ENABLED = "http.protocol.cookie-parsing-enabled"; + + /** * Defines {@link CookiePolicy cookie policy} to be used for cookie management. *
* This parameter expects a value of type {@link String}.
@@ -239,6 +247,28 @@
setParameter(PROTOCOL_VERSION, version);
}
+ /**
+ * Tests if cookie parsing is enabled.
+ *
+ * @return the cookieParsingEnabled flag
+ *
+ * @see #COOKIE_PARSING_ENABLED
+ */
+ public boolean isCookieParsingEnabled() {
+ return getBooleanParameter(COOKIE_PARSING_ENABLED, true);
+ }
+
+ /**
+ * Enables/disables cookie parsing.
+ *
+ * @param cookieParsingEnabled true if cookie parsing should be enabled,
+ * false otherwise
+ *
+ * @see #COOKIE_PARSING_ENABLED
+ */
+ public void setCookieParsingEnabled(boolean cookieParsingEnabled) {
+ setBooleanParameter(COOKIE_PARSING_ENABLED, cookieParsingEnabled);
+ }
/**
* Returns {@link CookiePolicy cookie policy} to be used by the
Index: src/test/org/apache/commons/httpclient/TestCookie.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
retrieving revision 1.25
diff -u -r1.25 TestCookie.java
--- src/test/org/apache/commons/httpclient/TestCookie.java 20 Oct 2003 22:26:28 -0000 1.25
+++ src/test/org/apache/commons/httpclient/TestCookie.java 28 Oct 2003 02:45:02 -0000
@@ -72,6 +72,7 @@
import java.util.TreeSet;
import java.util.Iterator;
import org.apache.commons.httpclient.cookie.*;
+import org.apache.commons.httpclient.methods.GetMethod;
/**
@@ -85,7 +86,7 @@
* @author Oleg Kalnichevski
* @version $Revision: 1.25 $
*/
-public class TestCookie extends TestCase {
+public class TestCookie extends TestNoHostBase {
// -------------------------------------------------------------- Constants
@@ -260,6 +261,27 @@
// ------------------------------------------------------------- More Tests
+ /**
+ * Test disabling cookie parsing.
+ */
+ public void testDisableParsing() throws Exception {
+ String headers =
+ "HTTP/1.1 401 OK\r\n" +
+ "Connection: close\r\n" +
+ "Content-Length: 0\r\n" +
+ "Set-Cookie: custno = 12345; comment=test; version=1," +
+ " name=John; version=1; max-age=600; secure; domain=.apache.org";
+
+ conn.addResponse(headers);
+
+ GetMethod get = new GetMethod("/");
+ get.getParams().setCookieParsingEnabled(false);
+ client.executeMethod(get);
+
+ assertEquals("Cookie parsing should have been disabled",
+ 0, client.getState().getCookies().length);
+ }
+
// see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5279
public void testQuotedExpiresAttribute() throws Exception {
String headerValue = "custno=12345;Expires='Thu, 01-Jan-2070 00:00:10 GMT'";
@@ -760,7 +782,7 @@
/**
* Tests default constructor.
*/
- public void testDefaultConsttuctor() {
+ public void testDefaultConstructor() {
Cookie dummy = new Cookie();
assertEquals( "noname=", dummy.toExternalForm() );
}