Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

Commit ddb7550

Browse files
author
leleliu008
committed
optimization: when responseSerializer is set a AFHTTPResponseSerializer instance
1 parent 2fba9eb commit ddb7550

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

AFNetworkActivityLogger/AFNetworkActivityConsoleLogger.m

+16-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,24 @@ - (void)URLSessionTaskDidFinish:(NSURLSessionTask *)task withResponseObject:(id)
7474
break;
7575
}
7676
} else {
77+
id responseBody = responseObject;
78+
79+
if(responseHeaderFields != nil && [responseObject isKindOfClass:[NSData class]]) {
80+
id contentTypeObj = [responseHeaderFields objectForKey:@"Content-Type"];
81+
if([contentTypeObj isKindOfClass:[NSString class]]) {
82+
NSString *contentType = contentTypeObj;
83+
if([contentType containsString:@"application/json"]
84+
|| [contentType containsString:@"application/xml"]
85+
|| [contentType containsString:@"application/x-www-form-urlencoded"]
86+
|| [contentType containsString:@"text/html"]) {
87+
responseBody = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
88+
}
89+
}
90+
}
91+
7792
switch (self.level) {
7893
case AFLoggerLevelDebug:
79-
NSLog(@"%ld '%@' [%.04f s]: %@ %@", (long)responseStatusCode, [[task.response URL] absoluteString], elapsedTime, responseHeaderFields, responseObject);
94+
NSLog(@"%ld '%@' [%.04f s]: %@ %@", (long)responseStatusCode, [[task.response URL] absoluteString], elapsedTime, responseHeaderFields, responseBody);
8095
break;
8196
case AFLoggerLevelInfo:
8297
NSLog(@"%ld '%@' [%.04f s]", (long)responseStatusCode, [[task.response URL] absoluteString], elapsedTime);

0 commit comments

Comments
 (0)