Skip to content

Commit d675f51

Browse files
committed
Merge branch 'master' of github.com:AFNetworking/AFNetworking
2 parents e55e84b + 1e3a335 commit d675f51

File tree

7 files changed

+92
-16
lines changed

7 files changed

+92
-16
lines changed

AFNetworking/AFURLSessionManager.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,14 @@ - (void)URLSession:(__unused NSURLSession *)session
132132
totalBytesSent:(int64_t)totalBytesSent
133133
totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend
134134
{
135-
self.uploadProgress.totalUnitCount = totalBytesExpectedToSend;
135+
int64_t totalUnitCount = totalBytesExpectedToSend;
136+
if(totalUnitCount == NSURLSessionTransferSizeUnknown) {
137+
NSString *contentLength = [task.originalRequest valueForHTTPHeaderField:@"Content-Length"];
138+
if(contentLength) {
139+
totalUnitCount = (int64_t) [contentLength longLongValue];
140+
}
141+
}
142+
self.uploadProgress.totalUnitCount = totalUnitCount;
136143
self.uploadProgress.completedUnitCount = totalBytesSent;
137144
}
138145

@@ -468,7 +475,15 @@ - (NSURLSessionUploadTask *)uploadTaskWithTask:(NSURLSessionUploadTask *)uploadT
468475

469476
AFURLSessionManagerTaskDelegate *delegate = [AFURLSessionManagerTaskDelegate delegateForManager:self completionHandler:completionHandler];
470477

471-
delegate.uploadProgress = [NSProgress progressWithTotalUnitCount:uploadTask.countOfBytesExpectedToSend];
478+
int64_t totalUnitCount = uploadTask.countOfBytesExpectedToSend;
479+
if(totalUnitCount == NSURLSessionTransferSizeUnknown) {
480+
NSString *contentLength = [uploadTask.originalRequest valueForHTTPHeaderField:@"Content-Length"];
481+
if(contentLength) {
482+
totalUnitCount = (int64_t) [contentLength longLongValue];
483+
}
484+
}
485+
486+
delegate.uploadProgress = [NSProgress progressWithTotalUnitCount:totalUnitCount];
472487
delegate.uploadProgress.pausingHandler = ^{
473488
[uploadTask suspend];
474489
};

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<img src="https://raw.github.com/AFNetworking/AFNetworking/assets/afnetworking-logo.png" alt="AFNetworking" title="AFNetworking">
33
</p>
44

5+
[![Build Status](https://travis-ci.org/AFNetworking/AFNetworking.png)](https://travis-ci.org/AFNetworking/AFNetworking)
6+
57
AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of the [Foundation URL Loading System](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html), extending the powerful high-level networking abstractions built into Cocoa. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use.
68

79
Perhaps the most important feature of all, however, is the amazing community of developers who use and contribute to AFNetworking every day. AFNetworking powers some of the most popular and critically-acclaimed apps on the iPhone, iPad, and Mac.

Tests/AFNetworking Tests.xcodeproj/project.pbxproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
2902D28117DF4E1200C81C5A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2902D27F17DF4E1200C81C5A /* InfoPlist.strings */; };
1414
2902D28D17DF4E2900C81C5A /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 29B9ED5C17DF4D350021E4D5 /* XCTest.framework */; };
1515
2902D28E17DF4E2A00C81C5A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2544EC35173BE382004117E8 /* Foundation.framework */; };
16-
2902D28F17DF4E2A00C81C5A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 29133DD617DE77ED006E0493 /* UIKit.framework */; };
1716
2902D29517DF4E2A00C81C5A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2902D29317DF4E2A00C81C5A /* InfoPlist.strings */; };
1817
2902D29C17DF4E3700C81C5A /* AFTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B9ED7617DF4D790021E4D5 /* AFTestCase.m */; };
1918
2902D29D17DF4E3800C81C5A /* AFTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B9ED7617DF4D790021E4D5 /* AFTestCase.m */; };
@@ -40,7 +39,6 @@
4039
/* Begin PBXFileReference section */
4140
2544EC35173BE382004117E8 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
4241
2544EC44173BE382004117E8 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
43-
2544EC46173BE382004117E8 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
4442
2544EC80173BFAA8004117E8 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
4543
2544EC83173BFAA8004117E8 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
4644
2544EC84173BFAA8004117E8 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
@@ -106,7 +104,6 @@
106104
buildActionMask = 2147483647;
107105
files = (
108106
2902D28D17DF4E2900C81C5A /* XCTest.framework in Frameworks */,
109-
2902D28F17DF4E2A00C81C5A /* UIKit.framework in Frameworks */,
110107
2902D28E17DF4E2A00C81C5A /* Foundation.framework in Frameworks */,
111108
3D56634E3A564CEE86172413 /* libPods-osx.a in Frameworks */,
112109
);
@@ -151,7 +148,6 @@
151148
25C4EC2A173D7DB30083E116 /* SystemConfiguration.framework */,
152149
2544EC35173BE382004117E8 /* Foundation.framework */,
153150
2544EC44173BE382004117E8 /* SenTestingKit.framework */,
154-
2544EC46173BE382004117E8 /* UIKit.framework */,
155151
2544EC80173BFAA8004117E8 /* Cocoa.framework */,
156152
29B9ED5C17DF4D350021E4D5 /* XCTest.framework */,
157153
2544EC82173BFAA8004117E8 /* Other Frameworks */,
@@ -614,6 +610,7 @@
614610
INFOPLIST_FILE = "OS X Tests/OS X Tests-Info.plist";
615611
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
616612
PRODUCT_NAME = "$(TARGET_NAME)";
613+
SDKROOT = macosx;
617614
WRAPPER_EXTENSION = xctest;
618615
};
619616
name = Debug;
@@ -640,6 +637,7 @@
640637
INFOPLIST_FILE = "OS X Tests/OS X Tests-Info.plist";
641638
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
642639
PRODUCT_NAME = "$(TARGET_NAME)";
640+
SDKROOT = macosx;
643641
WRAPPER_EXTENSION = xctest;
644642
};
645643
name = Release;

Tests/Schemes/OS X Tests.xcscheme

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,26 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "7F80D170FBDE4B6CAFA74110"
17+
BlueprintIdentifier = "FF3A4367F4A94D26A35ADC66"
1818
BuildableName = "libPods-osx.a"
1919
BlueprintName = "Pods-osx"
2020
ReferencedContainer = "container:Pods/Pods.xcodeproj">
2121
</BuildableReference>
2222
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "YES"
26+
buildForProfiling = "NO"
27+
buildForArchiving = "NO"
28+
buildForAnalyzing = "NO">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "2902D28B17DF4E2900C81C5A"
32+
BuildableName = "OS X Tests.xctest"
33+
BlueprintName = "OS X Tests"
34+
ReferencedContainer = "container:AFNetworking Tests.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
2337
</BuildActionEntries>
2438
</BuildAction>
2539
<TestAction
@@ -32,8 +46,8 @@
3246
skipped = "NO">
3347
<BuildableReference
3448
BuildableIdentifier = "primary"
35-
BlueprintIdentifier = "2544EC94173BFAA8004117E8"
36-
BuildableName = "OS X Tests.octest"
49+
BlueprintIdentifier = "2902D28B17DF4E2900C81C5A"
50+
BuildableName = "OS X Tests.xctest"
3751
BlueprintName = "OS X Tests"
3852
ReferencedContainer = "container:AFNetworking Tests.xcodeproj">
3953
</BuildableReference>

Tests/Schemes/iOS Tests.xcscheme

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,26 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "DA933E64A2B04B09A021A4AD"
17+
BlueprintIdentifier = "FFF3BD339AD244DFA4115EC4"
1818
BuildableName = "libPods-ios.a"
1919
BlueprintName = "Pods-ios"
2020
ReferencedContainer = "container:Pods/Pods.xcodeproj">
2121
</BuildableReference>
2222
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "YES"
26+
buildForProfiling = "NO"
27+
buildForArchiving = "NO"
28+
buildForAnalyzing = "NO">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "2902D27717DF4E1100C81C5A"
32+
BuildableName = "iOS Tests.xctest"
33+
BlueprintName = "iOS Tests"
34+
ReferencedContainer = "container:AFNetworking Tests.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
2337
</BuildActionEntries>
2438
</BuildAction>
2539
<TestAction
@@ -32,8 +46,8 @@
3246
skipped = "NO">
3347
<BuildableReference
3448
BuildableIdentifier = "primary"
35-
BlueprintIdentifier = "2544EC42173BE382004117E8"
36-
BuildableName = "iOS Tests.octest"
49+
BlueprintIdentifier = "2902D27717DF4E1100C81C5A"
50+
BuildableName = "iOS Tests.xctest"
3751
BlueprintName = "iOS Tests"
3852
ReferencedContainer = "container:AFNetworking Tests.xcodeproj">
3953
</BuildableReference>

Tests/Tests/AFHTTPRequestOperationTests.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,37 @@ -(void)testThatCompletionBlockForBatchRequestsIsFiredAfterAllOperationCompletion
355355
expect(completionBlockFiredAfterOtherBlocks).will.beTruthy();
356356
}
357357

358+
- (void)testThatOperationInvokesFailureCompletionBlockWithErrorOnWritingStreamFailure {
359+
__block NSError *blockError;
360+
361+
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/get" relativeToURL:self.baseURL]];
362+
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
363+
364+
NSError *streamError = [NSError errorWithDomain:NSStreamSocketSSLErrorDomain code:0 userInfo:nil];
365+
366+
[operation setOutputStream:({
367+
id mockStream = [OCMockObject mockForClass:[NSOutputStream class]];
368+
[[[mockStream stub] andReturn:streamError] streamError];
369+
[[[mockStream stub] andReturnValue:@NO] hasSpaceAvailable];
370+
371+
// "Note that currently partial mocks cannot be created for instances of toll-free bridged classes". Thus, we have to fully mock it
372+
[[mockStream stub] scheduleInRunLoop:OCMOCK_ANY forMode:OCMOCK_ANY];
373+
[[mockStream stub] open];
374+
[[mockStream stub] close];
375+
376+
mockStream;
377+
})];
378+
379+
// AFHTTPOperation currently does not have a default response serializer
380+
[operation setResponseSerializer:[AFHTTPResponseSerializer serializer]];
381+
382+
[operation setCompletionBlockWithSuccess:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) {
383+
blockError = error;
384+
}];
385+
386+
[operation start];
387+
expect([operation isFinished]).will.beTruthy();
388+
expect(blockError).will.equal(streamError);
389+
}
390+
358391
@end

Tests/Tests/AFHTTPSerializationTests.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ - (void)testThatAFHTTPResponseSerializationHandlesAll2XXCodes {
3838
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:statusCode HTTPVersion:@"1.1" headerFields:@{@"Content-Type": @"text/html"}];
3939

4040
AFHTTPResponseSerializer *serializer = [AFHTTPResponseSerializer serializer];
41-
XCTAssert([serializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %d should be acceptable", statusCode);
41+
XCTAssert([serializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %@ should be acceptable", @(statusCode));
4242

4343
NSError *error = nil;
4444
[serializer validateResponse:response data:[@"text" dataUsingEncoding:NSUTF8StringEncoding] error:&error];
4545

46-
XCTAssertNil(error, @"Error handling status code %d", statusCode);
46+
XCTAssertNil(error, @"Error handling status code %@", @(statusCode));
4747
}];
4848
}
4949

@@ -53,12 +53,12 @@ - (void)testThatAFHTTPResponseSerializationFailsAll4XX5XXStatusCodes {
5353
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:statusCode HTTPVersion:@"1.1" headerFields:@{@"Content-Type": @"text/html"}];
5454

5555
AFHTTPResponseSerializer *serializer = [AFHTTPResponseSerializer serializer];
56-
XCTAssert(![serializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %d should not be acceptable", statusCode);
56+
XCTAssert(![serializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %@ should not be acceptable", @(statusCode));
5757

5858
NSError *error = nil;
5959
[serializer validateResponse:response data:[@"text" dataUsingEncoding:NSUTF8StringEncoding] error:&error];
6060

61-
XCTAssertNotNil(error, @"Did not fail handling status code %d",statusCode);
61+
XCTAssertNotNil(error, @"Did not fail handling status code %@",@(statusCode));
6262
}];
6363
}
6464

0 commit comments

Comments
 (0)