Skip to content

Commit

Permalink
optimization: when responseSerializer is set a AFHTTPResponseSerializ…
Browse files Browse the repository at this point in the history
…er instance
  • Loading branch information
leleliu008 committed Jun 8, 2018
1 parent 2fba9eb commit ddb7550
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion AFNetworkActivityLogger/AFNetworkActivityConsoleLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,24 @@ - (void)URLSessionTaskDidFinish:(NSURLSessionTask *)task withResponseObject:(id)
break;
}
} else {
id responseBody = responseObject;

if(responseHeaderFields != nil && [responseObject isKindOfClass:[NSData class]]) {
id contentTypeObj = [responseHeaderFields objectForKey:@"Content-Type"];
if([contentTypeObj isKindOfClass:[NSString class]]) {
NSString *contentType = contentTypeObj;
if([contentType containsString:@"application/json"]
|| [contentType containsString:@"application/xml"]
|| [contentType containsString:@"application/x-www-form-urlencoded"]
|| [contentType containsString:@"text/html"]) {
responseBody = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
}
}
}

switch (self.level) {
case AFLoggerLevelDebug:
NSLog(@"%ld '%@' [%.04f s]: %@ %@", (long)responseStatusCode, [[task.response URL] absoluteString], elapsedTime, responseHeaderFields, responseObject);
NSLog(@"%ld '%@' [%.04f s]: %@ %@", (long)responseStatusCode, [[task.response URL] absoluteString], elapsedTime, responseHeaderFields, responseBody);
break;
case AFLoggerLevelInfo:
NSLog(@"%ld '%@' [%.04f s]", (long)responseStatusCode, [[task.response URL] absoluteString], elapsedTime);
Expand Down

0 comments on commit ddb7550

Please sign in to comment.