我想知道哪个方法是验证部分,它将识别响应中的缓存控制标头,并将调用connection:willCacheResponse:
委托。
因为我在这里定制了响应标头,并且期望NSURLConnection
调用connection:willCacheResponse:
,但这种情况并未发生。
- (void)connection:(NSURLConnection __unused *)connection
didReceiveResponse:(NSURLResponse *)回复 {
NSHTTPURLResponse *httpresponse = (NSHTTPURLResponse *)response;
NSLog(@"headers : %@", [httpresponse allHeaderFields]);
NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary];
[mutableDictionary addEntriesFromDictionary:[httpresponse allHeaderFields]];
[mutableDictionary setObject:@"public, must-revalidate, max-age=300000" forKey:@"Cache-Control"];
NSURLRequest *urlRequest = [connection currentRequest];
NSInteger statusCode = 200;
//id headerFields = nil;
NSURL *urlString = urlRequest.URL;
NSString* HTTPVersion = nil;
SEL selector = NSSelectorFromString(@"initWithURL:statusCode:HTTPVersion:headerFields:");
NSMethodSignature *signature = [self methodSignatureForSelector:selector];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:signature];
[inv setTarget:httpresponse];
[inv setSelector:selector];
[inv setArgument:&urlString atIndex:2];
[inv setArgument:&statusCode atIndex:3];
[inv setArgument:&mutableDictionary atIndex:5];
[inv setArgument:&HTTPVersion atIndex:4];
[inv invoke];
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)self.response;
int code = [httpResponse statusCode];
NSLog(@"response status code : %d", code);
if ([self.response respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog(@"Header Discription:%@", [dictionary description]);
}
[self.outputStream open];
}