asihttp 源码分析 之四 session

session 相关的变量

// In memory caches of credentials, used on when useSessionPersistence is YES

staticNSMutableArray*sessionCredentialsStore=nil;

static NSMutableArray *sessionProxyCredentialsStore = nil;

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

// We keep track of cookies we have received here so we can remove them from the sharedHTTPCookieStorage laterstatic 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];

[newCredentialssetObject:[selfpassword]forKey:(NSString*)kCFHTTPAuthenticationPassword];

相关推荐