[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit/cookies CookieListener.java,NONE,1.1 Cook
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-06-17 11:08:29
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/cookies
In directory sc8-pr-cvs1:/tmp/cvs-serv13759/src/com/meterware/httpunit/cookies
Modified Files:
Cookie.java CookieJar.java
Added Files:
CookieListener.java CookieProperties.java
Log Message:
Add cookie leniency and callbacks
***** Error reading new file[Errno 2] No such file or directory: 'CookieListener.java'
***** Error reading new file[Errno 2] No such file or directory: 'CookieProperties.java'
Index: Cookie.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/cookies/Cookie.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Cookie.java 4 Nov 2002 21:01:37 -0000 1.3
+++ Cookie.java 17 Jun 2003 11:08:25 -0000 1.4
@@ -111,7 +111,12 @@
boolean mayBeSentTo( URL url ) {
if (getDomain() == null) return true;
- return acceptHost( getDomain(), url.getHost() ) && url.getPath().startsWith( getPath() );
+ return acceptHost( getDomain(), url.getHost() ) && acceptPath( getPath(), url.getPath() );
+ }
+
+
+ private boolean acceptPath( String pathPattern, String hostPath ) {
+ return !CookieProperties.isPathMatchingStrict() || hostPath.startsWith( pathPattern );
}
Index: CookieJar.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/cookies/CookieJar.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CookieJar.java 23 May 2003 21:52:57 -0000 1.3
+++ CookieJar.java 17 Jun 2003 11:08:25 -0000 1.4
@@ -328,13 +328,21 @@
if (cookie.getPath() == null) {
cookie.setPath( getParentPath( _sourceURL.getPath() ) );
} else {
- if (!pathAttributeIsValid( _sourceURL.getPath(), cookie.getPath() )) return false;
+ int status = getPathAttributeStatus( cookie.getPath(), _sourceURL.getPath() );
+ if (status != CookieListener.ACCEPTED) {
+ reportCookieRejected( status, cookie.getPath(), cookie.getName() );
+ return false;
+ }
}
if (cookie.getDomain() == null) {
cookie.setDomain( _sourceURL.getHost() );
} else {
- if (!domainAttributeIsValid( cookie.getDomain(), _sourceURL.getHost() )) return false;
+ int status = getDomainAttributeStatus( cookie.getDomain(), _sourceURL.getHost() );
+ if (status != CookieListener.ACCEPTED) {
+ reportCookieRejected( status, cookie.getDomain(), cookie.getName() );
+ return false;
+ }
}
return true;
@@ -347,26 +355,35 @@
}
- private boolean pathAttributeIsValid( String sourcePath, String pathAttribute ) {
- return sourcePath.length() == 0 || sourcePath.startsWith( pathAttribute );
+ private int getPathAttributeStatus( String pathAttribute, String sourcePath ) {
+ if (!CookieProperties.isPathMatchingStrict() || sourcePath.length() == 0 || sourcePath.startsWith( pathAttribute )) {
+ return CookieListener.ACCEPTED;
+ } else {
+ return CookieListener.PATH_NOT_PREFIX;
+ }
}
- private boolean domainAttributeIsValid( String domainAttribute, String sourceHost ) {
- if (!domainAttribute.startsWith(".")) return false;
- if (domainAttribute.lastIndexOf('.') == 0) return false;
- if (!sourceHost.endsWith( domainAttribute )) return false;
- if (!isLenientMatching() && sourceHost.lastIndexOf( domainAttribute ) > sourceHost.indexOf( '.' )) return false;
- return true;
+ private int getDomainAttributeStatus( String domainAttribute, String sourceHost ) {
+ if (!domainAttribute.startsWith(".")) {
+ return CookieListener.DOMAIN_NO_STARTING_DOT;
+ } else if (domainAttribute.lastIndexOf('.') == 0) {
+ return CookieListener.DOMAIN_ONE_DOT;
+ } else if (!sourceHost.endsWith( domainAttribute )) {
+ return CookieListener.DOMAIN_NOT_SOURCE_SUFFIX;
+ } else if (CookieProperties.isDomainMatchingStrict() &&
+ sourceHost.lastIndexOf( domainAttribute ) > sourceHost.indexOf( '.' )) {
+ return CookieListener.DOMAIN_TOO_MANY_LEVELS;
+ } else {
+ return CookieListener.ACCEPTED;
+ }
}
- // set this to false to reject cookies when the host is of the form HD where D is the explicit domain attribute
- // and H contains a dot. Apparently, most browsers are lenient.
- private boolean isLenientMatching() {
- return true;
+ private boolean reportCookieRejected( int reason, String attribute, String source ) {
+ CookieProperties.reportCookieRejected( reason, attribute, source );
+ return false;
}
-
}
|