? fix11080.diff ? .fix11080.diff.swp ? java/org/apache/commons/httpclient/.Authenticator.java.swp ? java/org/apache/commons/httpclient/.HttpMethodBase.java.swp ? test/org/apache/commons/httpclient/.TestAuthenticator.java.swp Index: java/org/apache/commons/httpclient/Authenticator.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Authenticator.java,v retrieving revision 1.20 diff -u -r1.20 Authenticator.java --- java/org/apache/commons/httpclient/Authenticator.java 22 Jul 2002 15:50:02 -0000 1.20 +++ java/org/apache/commons/httpclient/Authenticator.java 23 Jul 2002 18:37:44 -0000 @@ -217,26 +217,24 @@ preemptive_str = PREEMPTIVE_DEFAULT; } boolean preemptive = ("true".equals(preemptive_str)); - log.debug("Using preemptive authorization: " + preemptive); - - //set the header preemptively if necessisary + //if there is no challenge, attempt to use preemptive authorization if (challengeHeader == null){ if (preemptive){ - Header requestHeader = Authenticator.basic(null, state, respHeader); - if(requestHeader != null) { // default credentials exist, add the header - log.debug("Preemptively sending default basic credentials"); + log.debug("Preemptively sending default basic credentials"); + try{ + Header requestHeader = Authenticator.basic(null, state, respHeader); method.addRequestHeader(requestHeader); return true; - } else { // no default credentials, don't add the header + } catch (HttpException httpe) { log.debug("No default credentials to preemptively send"); return false; - } - } else { + } + } else { //no challenge and no default creds so do nothing return false; } } - log.debug("challenge header is: " + challengeHeader); + log.debug("Attempting to authenticate challenge: " + challengeHeader); // Get the challenge from the header Index: test/org/apache/commons/httpclient/TestAuthenticator.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java,v retrieving revision 1.10 diff -u -r1.10 TestAuthenticator.java --- test/org/apache/commons/httpclient/TestAuthenticator.java 18 Jul 2002 17:05:51 -0000 1.10 +++ test/org/apache/commons/httpclient/TestAuthenticator.java 23 Jul 2002 18:37:45 -0000 @@ -244,7 +244,16 @@ assertTrue(null == method.getRequestHeader("Authorization")); } - public void testPreemptiveAuthorizationTrue() throws Exception { + public void testPreemptiveAuthorizationTrueNoCreds() throws Exception { + HttpState state = new HttpState(); + HttpMethod method = new SimpleHttpMethod(null); + + System.getProperties().setProperty(Authenticator.PREEMPTIVE_PROPERTY, "true"); + assertTrue(! Authenticator.authenticate(method,state)); + assertTrue(null == method.getRequestHeader("Authorization")); + } + + public void testPreemptiveAuthorizationTrueWithCreds() throws Exception { HttpState state = new HttpState(); HttpMethod method = new SimpleHttpMethod(null); state.setCredentials(null, new UsernamePasswordCredentials("username","password"));