Fix stupid bug that would prevent session cookies from being cleared
Revised cookie tests Use setter for setting response headers
Showing
3 changed files
with
13 additions
and
8 deletions
| @@ -50,10 +50,10 @@ typedef enum _ASINetworkErrorType { | @@ -50,10 +50,10 @@ typedef enum _ASINetworkErrorType { | ||
| 50 | // Can be used to manually insert cookie headers to a request, but it's more likely that sessionCookies will do this for you | 50 | // Can be used to manually insert cookie headers to a request, but it's more likely that sessionCookies will do this for you |
| 51 | NSMutableArray *requestCookies; | 51 | NSMutableArray *requestCookies; |
| 52 | 52 | ||
| 53 | - // Will be populated with Cookies | 53 | + // Will be populated with cookies |
| 54 | NSArray *responseCookies; | 54 | NSArray *responseCookies; |
| 55 | 55 | ||
| 56 | - // If use cokie persistance is true, network requests will present valid cookies from previous requests | 56 | + // If use useCookiePersistance is true, network requests will present valid cookies from previous requests |
| 57 | BOOL useCookiePersistance; | 57 | BOOL useCookiePersistance; |
| 58 | 58 | ||
| 59 | // If useKeychainPersistance is true, network requests will attempt to read credentials from the keychain, and will save them in the keychain when they are successfully presented | 59 | // If useKeychainPersistance is true, network requests will attempt to read credentials from the keychain, and will save them in the keychain when they are successfully presented |
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | // ASIHTTPRequest.m | 2 | // ASIHTTPRequest.m |
| 3 | // | 3 | // |
| 4 | // Created by Ben Copsey on 04/10/2007. | 4 | // Created by Ben Copsey on 04/10/2007. |
| 5 | -// Copyright 2007-2008 All-Seeing Interactive. All rights reserved. | 5 | +// Copyright 2007-2009 All-Seeing Interactive. All rights reserved. |
| 6 | // | 6 | // |
| 7 | // A guide to the main features is available at: | 7 | // A guide to the main features is available at: |
| 8 | // http://allseeing-i.com/ASIHTTPRequest | 8 | // http://allseeing-i.com/ASIHTTPRequest |
| @@ -719,8 +719,8 @@ static NSError *ASIUnableToCreateRequestError; | @@ -719,8 +719,8 @@ static NSError *ASIUnableToCreateRequestError; | ||
| 719 | BOOL isAuthenticationChallenge = NO; | 719 | BOOL isAuthenticationChallenge = NO; |
| 720 | CFHTTPMessageRef headers = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader); | 720 | CFHTTPMessageRef headers = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader); |
| 721 | if (CFHTTPMessageIsHeaderComplete(headers)) { | 721 | if (CFHTTPMessageIsHeaderComplete(headers)) { |
| 722 | - responseHeaders = (NSDictionary *)CFHTTPMessageCopyAllHeaderFields(headers); | 722 | + [self setResponseHeaders:(NSDictionary *)CFHTTPMessageCopyAllHeaderFields(headers)]; |
| 723 | - responseStatusCode = CFHTTPMessageGetResponseStatusCode(headers); | 723 | + [self setResponseStatusCode:CFHTTPMessageGetResponseStatusCode(headers)]; |
| 724 | 724 | ||
| 725 | // Is the server response a challenge for credentials? | 725 | // Is the server response a challenge for credentials? |
| 726 | isAuthenticationChallenge = (responseStatusCode == 401); | 726 | isAuthenticationChallenge = (responseStatusCode == 401); |
| @@ -1148,8 +1148,7 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1148,8 +1148,7 @@ static NSError *ASIUnableToCreateRequestError; | ||
| 1148 | + (void)setSessionCookies:(NSMutableArray *)newSessionCookies | 1148 | + (void)setSessionCookies:(NSMutableArray *)newSessionCookies |
| 1149 | { | 1149 | { |
| 1150 | // Remove existing cookies from the persistent store | 1150 | // Remove existing cookies from the persistent store |
| 1151 | - NSHTTPCookie *cookie; | 1151 | + for (NSHTTPCookie *cookie in [ASIHTTPRequest sessionCookies]) { |
| 1152 | - for (cookie in newSessionCookies) { | ||
| 1153 | [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; | 1152 | [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; |
| 1154 | } | 1153 | } |
| 1155 | [sessionCookies release]; | 1154 | [sessionCookies release]; |
| @@ -168,7 +168,7 @@ | @@ -168,7 +168,7 @@ | ||
| 168 | { | 168 | { |
| 169 | progress = newProgress; | 169 | progress = newProgress; |
| 170 | } | 170 | } |
| 171 | - | 171 | + |
| 172 | 172 | ||
| 173 | 173 | ||
| 174 | - (void)testCookies | 174 | - (void)testCookies |
| @@ -263,11 +263,17 @@ | @@ -263,11 +263,17 @@ | ||
| 263 | success = [html isEqualToString:@"I have 'Test Value' as the value of 'ASIHTTPRequestTestCookie'"]; | 263 | success = [html isEqualToString:@"I have 'Test Value' as the value of 'ASIHTTPRequestTestCookie'"]; |
| 264 | STAssertTrue(success,@"Custom cookie not presented to the server with cookie persistance OFF"); | 264 | STAssertTrue(success,@"Custom cookie not presented to the server with cookie persistance OFF"); |
| 265 | 265 | ||
| 266 | + | ||
| 267 | + | ||
| 266 | // Test removing all cookies works | 268 | // Test removing all cookies works |
| 267 | [ASIHTTPRequest clearSession]; | 269 | [ASIHTTPRequest clearSession]; |
| 270 | + NSArray *sessionCookies = [ASIHTTPRequest sessionCookies]; | ||
| 271 | + success = ([sessionCookies count] == 0); | ||
| 272 | + STAssertTrue(success,@"Cookies not removed"); | ||
| 268 | 273 | ||
| 269 | url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/read_cookie"] autorelease]; | 274 | url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/read_cookie"] autorelease]; |
| 270 | request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 275 | request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
| 276 | + [request setUseCookiePersistance:YES]; | ||
| 271 | [request start]; | 277 | [request start]; |
| 272 | html = [request dataString]; | 278 | html = [request dataString]; |
| 273 | success = [html isEqualToString:@"No cookie exists"]; | 279 | success = [html isEqualToString:@"No cookie exists"]; |
-
Please register or login to post a comment