读书人

asihttp 源码分析 之4 session

发布时间: 2012-07-02 17:46:22 作者: rapoo

asihttp 源码分析 之四 session

session 相关的变量

// In memory caches of credentials, used on when useSessionPersistence is YES
static NSMutableArray *sessionCredentialsStore = nil;
static NSMutableArray *sessionProxyCredentialsStore = nil;

// This lock mediates access to session credentials
static NSRecursiveLock *sessionCredentialsLock = nil;

// We keep track of cookies we have received here so we can remove them from the sharedHTTPCookieStorage later
static NSMutableArray *sessionCookies = nil;

?

session信息被存储的内存中。

?

开启session ,useSessionPersistence = yes。

?

- (void)readResponseHeaders方法中生产并存储session信息

?

 // Authentication succeeded, or no authentication was required if (![self authenticationNeeded]) {  // Did we get here without an authentication challenge? (which can happen when shouldPresentCredentialsBeforeChallenge is YES and basic auth was successful)  if (!requestAuthentication && [self username] && [self password] && [self useSessionPersistence]) {      NSMutableDictionary *newCredentials = [NSMutableDictionary dictionaryWithCapacity:2];   [newCredentials setObject:[self username] forKey:(NSString *)kCFHTTPAuthenticationUsername];   [newCredentials setObject:[self password] forKey:(NSString *)kCFHTTPAuthenticationPassword];      // Store the credentials in the session    NSMutableDictionary *sessionCredentials = [NSMutableDictionary dictionary];   [sessionCredentials setObject:newCredentials forKey:@"Credentials"];   [sessionCredentials setObject:[self url] forKey:@"URL"];   [sessionCredentials setObject:(NSString *)kCFHTTPAuthenticationSchemeBasic forKey:@"AuthenticationScheme"];   [[self class] storeAuthenticationCredentialsInSessionStore:sessionCredentials];  } }

?

?

?[newCredentials setObject:[self username] forKey:(NSString *)kCFHTTPAuthenticationUsername];
?? [newCredentials setObject:[self password] forKey:(NSString *)kCFHTTPAuthenticationPassword];

读书人网 >移动开发

热点推荐