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
*/
+ (NSString *) selectHeaderAccept:(NSArray *)accepts
{
+ (NSString *) selectHeaderAccept:(NSArray *)accepts {
if (accepts == nil || [accepts count] == 0) {
return @"";
}
NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]];
[accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[lowerAccepts addObject:[obj lowercaseString]];
}];
if ([lowerAccepts containsObject:@"application/json"]) {
for (NSString *string in accepts) {
NSString * lowerAccept = [string lowercaseString];
if([lowerAccept containsString:@"application/json"]) {
return @"application/json";
}
else {
return [lowerAccepts componentsJoinedByString:@", "];
[lowerAccepts addObject:lowerAccept];
}
if(lowerAccepts.count == 1){
return [lowerAccepts firstObject];
}
return [lowerAccepts componentsJoinedByString:@", "];
}
/*