fix bug with content type accessors in cases where the content type response header is nil

This commit is contained in:
Jeff Arena
2011-01-10 16:10:30 -08:00
parent 35ae5c8717
commit d3a1059d68

View File

@@ -220,20 +220,24 @@
}
- (BOOL)isHTML {
return [[self contentType] rangeOfString:@"text/html" options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0 ||
[self isXHTML];
NSString* contentType = [self contentType];
return contentType && ([contentType rangeOfString:@"text/html" options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0 ||
[self isXHTML]);
}
- (BOOL)isXHTML {
return [[self contentType] rangeOfString:@"application/xhtml+xml" options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0;
NSString* contentType = [self contentType];
return contentType && [contentType rangeOfString:@"application/xhtml+xml" options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0;
}
- (BOOL)isXML {
return [[self contentType] rangeOfString:@"application/xml" options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0;
NSString* contentType = [self contentType];
return contentType && [contentType rangeOfString:@"application/xml" options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0;
}
- (BOOL)isJSON {
return [[self contentType] rangeOfString:@"application/json" options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0;
NSString* contentType = [self contentType];
return contentType && [contentType rangeOfString:@"application/json" options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0;
}
@end