Ben Copsey

Fix stupid bug that would prevent session cookies from being cleared

Revised cookie tests
Use setter for setting response headers
... ... @@ -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
... ...
... ... @@ -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 @@ static NSError *ASIUnableToCreateRequestError;
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 @@ static NSError *ASIUnableToCreateRequestError;
+ (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];
... ...
... ... @@ -168,7 +168,7 @@
{
progress = newProgress;
}
- (void)testCookies
... ... @@ -263,11 +263,17 @@
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"];
... ...