Support for extended 'application/json' HeaderAccept types

This commit is contained in:
Mateusz Mackowiak 2015-12-08 18:52:59 +01:00
parent 258bb27f30
commit a01dfb693b

View File

@ -128,24 +128,22 @@ static void (^reachabilityChangeBlock)(int);
/* /*
* Detect `Accept` from accepts * Detect `Accept` from accepts
*/ */
+ (NSString *) selectHeaderAccept:(NSArray *)accepts + (NSString *) selectHeaderAccept:(NSArray *)accepts {
{
if (accepts == nil || [accepts count] == 0) { if (accepts == nil || [accepts count] == 0) {
return @""; return @"";
} }
NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]]; NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]];
[accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { for (NSString *string in accepts) {
[lowerAccepts addObject:[obj lowercaseString]]; NSString * lowerAccept = [string lowercaseString];
}]; if([lowerAccept containsString:@"application/json"]) {
return @"application/json";
}
if ([lowerAccepts containsObject:@"application/json"]) { [lowerAccepts addObject:lowerAccept];
return @"application/json";
} }
else { if(lowerAccepts.count == 1){
return [lowerAccepts componentsJoinedByString:@", "]; return [lowerAccepts firstObject];
} }
return [lowerAccepts componentsJoinedByString:@", "];
} }
/* /*