diff --git a/Classes/Network/FLEXNetworkTransactionDetailTableViewController.m b/Classes/Network/FLEXNetworkTransactionDetailTableViewController.m index c782132f6a..c8503f6aff 100644 --- a/Classes/Network/FLEXNetworkTransactionDetailTableViewController.m +++ b/Classes/Network/FLEXNetworkTransactionDetailTableViewController.m @@ -403,7 +403,7 @@ + (FLEXNetworkDetailSection *)postBodySectionForTransaction:(FLEXNetworkTransact NSString *contentType = [transaction.request valueForHTTPHeaderField:@"Content-Type"]; if ([contentType hasPrefix:@"application/x-www-form-urlencoded"]) { NSString *bodyString = [NSString stringWithCString:[self postBodyDataForTransaction:transaction].bytes encoding:NSUTF8StringEncoding]; - postBodySection.rows = [self networkDetailRowsFromDictionary:[FLEXUtility dictionaryFromQuery:bodyString]]; + postBodySection.rows = [self networkDetailRowsFromQueryItems:[FLEXUtility itemsFromQueryString:bodyString]]; } } return postBodySection; @@ -411,10 +411,10 @@ + (FLEXNetworkDetailSection *)postBodySectionForTransaction:(FLEXNetworkTransact + (FLEXNetworkDetailSection *)queryParametersSectionForTransaction:(FLEXNetworkTransaction *)transaction { - NSDictionary *queryDictionary = [FLEXUtility dictionaryFromQuery:transaction.request.URL.query]; + NSArray *queries = [FLEXUtility itemsFromQueryString:transaction.request.URL.query]; FLEXNetworkDetailSection *querySection = [FLEXNetworkDetailSection new]; querySection.title = @"Query Parameters"; - querySection.rows = [self networkDetailRowsFromDictionary:queryDictionary]; + querySection.rows = [self networkDetailRowsFromQueryItems:queries]; return querySection; } @@ -432,8 +432,9 @@ + (FLEXNetworkDetailSection *)responseHeadersSectionForTransaction:(FLEXNetworkT + (NSArray *)networkDetailRowsFromDictionary:(NSDictionary *)dictionary { - NSMutableArray *rows = [NSMutableArray arrayWithCapacity:dictionary.count]; + NSMutableArray *rows = [NSMutableArray new]; NSArray *sortedKeys = [dictionary.allKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; + for (NSString *key in sortedKeys) { id value = dictionary[key]; FLEXNetworkDetailRow *row = [FLEXNetworkDetailRow new]; @@ -441,6 +442,25 @@ + (FLEXNetworkDetailSection *)responseHeadersSectionForTransaction:(FLEXNetworkT row.detailText = [value description]; [rows addObject:row]; } + + return rows.copy; +} + ++ (NSArray *)networkDetailRowsFromQueryItems:(NSArray *)items +{ + // Sort the items by name + items = [items sortedArrayUsingComparator:^NSComparisonResult(NSURLQueryItem *item1, NSURLQueryItem *item2) { + return [item1.name caseInsensitiveCompare:item2.name]; + }]; + + NSMutableArray *rows = [NSMutableArray new]; + for (NSURLQueryItem *item in items) { + FLEXNetworkDetailRow *row = [FLEXNetworkDetailRow new]; + row.title = item.name; + row.detailText = item.value; + [rows addObject:row]; + } + return [rows copy]; } diff --git a/Classes/Utility/FLEXUtility.h b/Classes/Utility/FLEXUtility.h index 1f2cdb0b9e..b4764db9fc 100644 --- a/Classes/Utility/FLEXUtility.h +++ b/Classes/Utility/FLEXUtility.h @@ -44,7 +44,7 @@ + (NSString *)stringFromRequestDuration:(NSTimeInterval)duration; + (NSString *)statusCodeStringFromURLResponse:(NSURLResponse *)response; + (BOOL)isErrorStatusCodeFromURLResponse:(NSURLResponse *)response; -+ (NSDictionary *)dictionaryFromQuery:(NSString *)query; ++ (NSArray *)itemsFromQueryString:(NSString *)query; + (NSString *)prettyJSONStringFromData:(NSData *)data; + (BOOL)isValidJSONData:(NSData *)data; + (NSData *)inflatedDataFromCompressedData:(NSData *)compressedData; diff --git a/Classes/Utility/FLEXUtility.m b/Classes/Utility/FLEXUtility.m index 93bc1a525c..d718ce9215 100644 --- a/Classes/Utility/FLEXUtility.m +++ b/Classes/Utility/FLEXUtility.m @@ -276,19 +276,17 @@ + (NSString *)statusCodeStringFromURLResponse:(NSURLResponse *)response + (BOOL)isErrorStatusCodeFromURLResponse:(NSURLResponse *)response { - NSIndexSet *errorStatusCodes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(400, 200)]; - if ([response isKindOfClass:[NSHTTPURLResponse class]]) { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; - return [errorStatusCodes containsIndex:httpResponse.statusCode]; + return httpResponse.statusCode >= 400; } return NO; } -+ (NSDictionary *)dictionaryFromQuery:(NSString *)query ++ (NSArray *)itemsFromQueryString:(NSString *)query { - NSMutableDictionary *queryDictionary = [NSMutableDictionary dictionary]; + NSMutableArray *items = [NSMutableArray new]; // [a=1, b=2, c=3] NSArray *queryComponents = [query componentsSeparatedByString:@"&"]; @@ -296,24 +294,14 @@ + (BOOL)isErrorStatusCodeFromURLResponse:(NSURLResponse *)response // [a, 1] NSArray *components = [keyValueString componentsSeparatedByString:@"="]; if (components.count == 2) { - NSString *key = [components.firstObject stringByRemovingPercentEncoding]; - id value = [components.lastObject stringByRemovingPercentEncoding]; - - // Handle multiple entries under the same key as an array - id existingEntry = queryDictionary[key]; - if (existingEntry) { - if ([existingEntry isKindOfClass:[NSArray class]]) { - value = [existingEntry arrayByAddingObject:value]; - } else { - value = @[existingEntry, value]; - } - } - - [queryDictionary setObject:value forKey:key]; + NSString *key = components.firstObject.stringByRemovingPercentEncoding; + NSString *value = components.lastObject.stringByRemovingPercentEncoding; + + [items addObject:[NSURLQueryItem queryItemWithName:key value:value]]; } } - return queryDictionary; + return items.copy; } + (NSString *)prettyJSONStringFromData:(NSData *)data