Permalink
Browse files

Fix stupid bug that would prevent session cookies from being cleared

Revised cookie tests
Use setter for setting response headers
  • Loading branch information...
1 parent 0add004 commit f3d43b2973e401357dce88dba4268bacd28b69bc @pokeb committed Feb 16, 2009
Showing with 13 additions and 8 deletions.
  1. +2 −2 ASIHTTPRequest.h
  2. +4 −5 ASIHTTPRequest.m
  3. +7 −1 ASIHTTPRequestTests.m
View
4 ASIHTTPRequest.h
@@ -50,10 +50,10 @@ typedef enum _ASINetworkErrorType {
// Can be used to manually insert cookie headers to a request, but it's more likely that sessionCookies will do this for you
NSMutableArray *requestCookies;
- // Will be populated with Cookies
+ // Will be populated with cookies
NSArray *responseCookies;
- // If use cokie persistance is true, network requests will present valid cookies from previous requests
+ // If use useCookiePersistance is true, network requests will present valid cookies from previous requests
BOOL useCookiePersistance;
// 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
View
9 ASIHTTPRequest.m
@@ -2,7 +2,7 @@
// ASIHTTPRequest.m
//
// Created by Ben Copsey on 04/10/2007.
-// Copyright 2007-2008 All-Seeing Interactive. All rights reserved.
+// Copyright 2007-2009 All-Seeing Interactive. All rights reserved.
//
// A guide to the main features is available at:
// http://allseeing-i.com/ASIHTTPRequest
@@ -719,8 +719,8 @@ - (BOOL)readResponseHeadersReturningAuthenticationFailure
BOOL isAuthenticationChallenge = NO;
CFHTTPMessageRef headers = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
if (CFHTTPMessageIsHeaderComplete(headers)) {
- responseHeaders = (NSDictionary *)CFHTTPMessageCopyAllHeaderFields(headers);
- responseStatusCode = CFHTTPMessageGetResponseStatusCode(headers);
+ [self setResponseHeaders:(NSDictionary *)CFHTTPMessageCopyAllHeaderFields(headers)];
+ [self setResponseStatusCode:CFHTTPMessageGetResponseStatusCode(headers)];
// Is the server response a challenge for credentials?
isAuthenticationChallenge = (responseStatusCode == 401);
@@ -1148,8 +1148,7 @@ + (NSMutableArray *)sessionCookies
+ (void)setSessionCookies:(NSMutableArray *)newSessionCookies
{
// Remove existing cookies from the persistent store
- NSHTTPCookie *cookie;
- for (cookie in newSessionCookies) {
+ for (NSHTTPCookie *cookie in [ASIHTTPRequest sessionCookies]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
[sessionCookies release];
View
8 ASIHTTPRequestTests.m
@@ -168,7 +168,7 @@ - (void)setProgress:(float)newProgress;
{
progress = newProgress;
}
-
+
- (void)testCookies
@@ -263,11 +263,17 @@ - (void)testCookies
success = [html isEqualToString:@"I have 'Test Value' as the value of 'ASIHTTPRequestTestCookie'"];
STAssertTrue(success,@"Custom cookie not presented to the server with cookie persistance OFF");
+
+
// Test removing all cookies works
[ASIHTTPRequest clearSession];
+ NSArray *sessionCookies = [ASIHTTPRequest sessionCookies];
+ success = ([sessionCookies count] == 0);
+ STAssertTrue(success,@"Cookies not removed");
url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/read_cookie"] autorelease];
request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
+ [request setUseCookiePersistance:YES];
[request start];
html = [request dataString];
success = [html isEqualToString:@"No cookie exists"];

0 comments on commit f3d43b2

Please sign in to comment.