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

optimization: when responseSerializer is set a AFHTTPResponseSerializer instance #51

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

leleliu008
Copy link

@leleliu008 leleliu008 commented Jun 8, 2018

when responseSerializer is set a AFHTTPResponseSerializer instance, the responseObject is NSData Type, in fact, the response body may be xml、html、x-www-form-urlencoded or other text format, in this case , we can according to Content-Type response header determine whether the response body is text, if the response body is text, we convert it to NSString to print it, beasuse it looks better.

@codecov-io
Copy link

codecov-io commented Jun 8, 2018

Codecov Report

Merging #51 into master will increase coverage by 0.24%.
The diff coverage is 95.95%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #51      +/-   ##
=========================================
+ Coverage   94.86%   95.1%   +0.24%     
=========================================
  Files           4       3       -1     
  Lines         292     388      +96     
  Branches       12       0      -12     
=========================================
+ Hits          277     369      +92     
- Misses         15      19       +4
Impacted Files Coverage Δ
Tests/AFNetworkingLoggerTests.m 96.42% <100%> (ø)
AFNetworkingLogger/AFNetworkingLogger.m 95.31% <100%> (ø)
AFNetworkingLogger/AFNetworkingConsoleLogger.m 90.27% <90.27%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2fba9eb...1120a96. Read the comment docs.

NSLog(@"%ld '%@' [%.04f s]: %@ %@", (long)responseStatusCode, [[task.response URL] absoluteString], elapsedTime, responseHeaderFields, responseObject);
break;
case AFLoggerLevelDebug: {
id responseBody = responseObject;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when log level is AFLoggerLevelDebug apply the optimization

@@ -265,5 +265,52 @@ - (void)testThatIndividualLoggerIsNotCalledWhenLoggerIsNilledOut {
[manager invalidateSessionCancelingTasks:YES];
}

- (void)testThatResponseSerializerIsAFHTTPResponseSerializerAndResponseBodyIsText {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the test case: when manager.responseSerializer = [AFHTTPResponseSerializer serializer]; and the http response body is text.

[manager invalidateSessionCancelingTasks:YES];
}

- (void)testThatResponseSerializerIsAFHTTPResponseSerializerAndResponseBodyIsNotText {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the test case: when manager.responseSerializer = [AFHTTPResponseSerializer serializer]; and the http response body is not text, for example, the response body is a image

…ode if ([request HTTPBody]) in AFNetworkActivityConsoleLogger.m
[self.logger startLogging];

[manager
POST:@"post"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the code _if ([request HTTPBody]) {
body = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
}_in AFNetworkActivityConsoleLogger.m is not test. so I find a POST request and has request body to cover it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants