Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@ on:
branches: [master]

jobs:
test:
runs-on: macOS-latest
httpbin:
runs-on: ubuntu-latest
steps:
- name: print env
- uses: actions-hub/docker/cli@master

- name: install httpbin
run: |
xcodebuild -version
docker pull kennethreitz/httpbin
docker run -p 80:80 kennethreitz/httpbin
shell: bash
ut:
runs-on: macOS-latest
steps:

- uses: actions/checkout@master

- name: install cocoapods
run: gem install cocoapods

- name: install dependencies
run: |
cd Example
pod install
shell: bash

- name: run test
run: xcodebuild test -workspace ./Example/YMHTTP.xcworkspace -scheme 'YMHTTP-Example' -destination 'platform=iOS Simulator,name=iPhone 11'
shell: bash
79 changes: 39 additions & 40 deletions Example/Tests/TestURLSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ @interface TestURLSession : XCTestCase
@implementation TestURLSession

- (void)testDataTaskWithURL {
NSString *urlString = @"http://httpbin.org/get?capital=testDataTaskWithURL";
NSString *urlString = @"http://0.0.0.0/get?capital=testDataTaskWithURL";
NSURL *url = [NSURL URLWithString:urlString];
XCTestExpectation *te = [self expectationWithDescription:@"GET testDataTaskWithURL: with a delegate"];
YMDataTask *d = [[YMDataTask alloc] initWithExpectation:te];
Expand All @@ -42,7 +42,7 @@ - (void)testDataTaskWithURLCompletionHandler {
}

- (void)dataTaskWithURLCompletionHandlerWithSession:(YMURLSession *)session {
NSString *urlString = @"http://httpbin.org/get?capital=China";
NSString *urlString = @"http://0.0.0.0/get?capital=China";
NSURL *url = [NSURL URLWithString:urlString];
XCTestExpectation *te =
[self expectationWithDescription:@"GET dataTaskWithURLCompletionHandlerWithSession: with a completion handler"];
Expand All @@ -68,7 +68,7 @@ - (void)dataTaskWithURLCompletionHandlerWithSession:(YMURLSession *)session {
}

- (void)testDataTaskWithRequest {
NSString *urlString = @"http://httpbin.org/get?capital=testDataTaskWithRequest";
NSString *urlString = @"http://0.0.0.0/get?capital=testDataTaskWithRequest";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
XCTestExpectation *te = [self expectationWithDescription:@"GET testDataTaskWithRequest: with a delegate"];
Expand All @@ -83,7 +83,7 @@ - (void)testDataTaskWithRequest {
}

- (void)testDataTaskWithURLRequestCompletionHandler {
NSString *urlString = @"http://httpbin.org/get?capital=testDataTaskWithURLRequestCompletionHandler";
NSString *urlString = @"http://0.0.0.0/get?capital=testDataTaskWithURLRequestCompletionHandler";
NSURL *url = [NSURL URLWithString:urlString];
XCTestExpectation *te =
[self expectationWithDescription:@"GET testDataTaskWithURLRequestCompletionHandler: with a completion handler"];
Expand Down Expand Up @@ -123,7 +123,7 @@ - (void)testDataTaskWithHttpInputStream {
@"pretium, augue non elementum imperdiet, diam ex vestibulum tortor, non ultrices ante enim iaculis ex.";
NSData *bodyData = [dataString dataUsingEncoding:NSUTF8StringEncoding];
for (NSString *method in httpMethods) {
NSString *urlString = [NSString stringWithFormat:@"https://httpbin.org/%@", [method lowercaseString]];
NSString *urlString = [NSString stringWithFormat:@"http://0.0.0.0/%@", [method lowercaseString]];
for (id contentType in @[ @"text/plain; charset=utf-8", [NSNull null] ]) {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
request.HTTPMethod = method;
Expand Down Expand Up @@ -189,7 +189,7 @@ - (void)testDataTaskWithHttpInputStream {
}

- (void)testGzippedDataTask {
NSString *urlString = @"http://httpbin.org/gzip";
NSString *urlString = @"http://0.0.0.0/gzip";
NSURL *url = [NSURL URLWithString:urlString];
XCTestExpectation *te = [self expectationWithDescription:@"GET testGzippedDataTask: with a delegate"];
YMDataTask *d = [[YMDataTask alloc] initWithExpectation:te];
Expand All @@ -201,7 +201,7 @@ - (void)testGzippedDataTask {
}

- (void)testDownloadTaskWithURL {
NSString *urlString = @"http://httpbin.org/image/png";
NSString *urlString = @"http://0.0.0.0/image/png";
NSURL *url = [NSURL URLWithString:urlString];
YMDownloadTask *d =
[[YMDownloadTask alloc] initWithTestCase:self
Expand All @@ -211,7 +211,7 @@ - (void)testDownloadTaskWithURL {
}

- (void)testDownloadTaskWithRequest {
NSString *urlString = @"http://httpbin.org/image/jepg";
NSString *urlString = @"http://0.0.0.0/image/jepg";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
YMDownloadTask *d =
Expand All @@ -233,7 +233,7 @@ - (void)downloadTaskWithRequestAndHandlerWithSession:(YMURLSession *)session {
XCTestExpectation *te =
[self expectationWithDescription:
@"Download GET downloadTaskWithRequestAndHandlerWithSession: with a completion handler"];
NSString *urlString = @"http://httpbin.org/image/svg";
NSString *urlString = @"http://0.0.0.0/image/svg";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
YMURLSessionTask *task =
Expand All @@ -254,7 +254,7 @@ - (void)downloadTaskWithRequestAndHandlerWithSession:(YMURLSession *)session {
- (void)testDownloadTaskWithURLAndHandler {
XCTestExpectation *te =
[self expectationWithDescription:@"Download GET testDownloadTaskWithURLAndHandler: with a completion handler"];
NSString *urlString = @"http://httpbin.org/image/webp";
NSString *urlString = @"http://0.0.0.0/image/webp";
NSURL *url = [NSURL URLWithString:urlString];

YMURLSessionConfiguration *config = [YMURLSessionConfiguration defaultSessionConfiguration];
Expand All @@ -276,7 +276,7 @@ - (void)testDownloadTaskWithURLAndHandler {
}

- (void)testGzippedDownloadTask {
NSString *urlString = @"http://httpbin.org/image/gzip";
NSString *urlString = @"http://0.0.0.0/image/gzip";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
YMDownloadTask *d =
Expand All @@ -291,7 +291,7 @@ - (void)testFinishTasksAndInvalidate {
XCTestExpectation *completionExpectation = [self
expectationWithDescription:@"GET testFinishTasksAndInvalidate: task completion before session invalidation"];

NSString *urlString = @"http://httpbin.org/get";
NSString *urlString = @"http://0.0.0.0/get";
NSURL *url = [NSURL URLWithString:urlString];
YMSessionDelegate *delegate = [YMSessionDelegate new];
delegate.invalidateExpectation = invalidateExpectation;
Expand Down Expand Up @@ -332,7 +332,7 @@ - (void)testTaskError {
}

- (void)testTaskCopy {
NSString *urlString = @"http://httpbin.org/get";
NSString *urlString = @"http://0.0.0.0/get";
NSURL *url = [NSURL URLWithString:urlString];
YMURLSessionConfiguration *config = [YMURLSessionConfiguration defaultSessionConfiguration];
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];
Expand All @@ -342,7 +342,7 @@ - (void)testTaskCopy {
}

- (void)testCancelTask {
NSString *urlString = @"http://httpbin.org/get";
NSString *urlString = @"http://0.0.0.0/get";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

Expand All @@ -365,7 +365,7 @@ - (void)testVerifyRequestHeaders {
YMURLSessionConfiguration *config = [YMURLSessionConfiguration defaultSessionConfiguration];
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];

NSString *urlString = @"http://httpbin.org/post";
NSString *urlString = @"http://0.0.0.0/post";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
Expand Down Expand Up @@ -400,7 +400,7 @@ - (void)testVerifyHttpAdditionalHeaders {
};
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];

NSString *urlString = @"http://httpbin.org/post";
NSString *urlString = @"http://0.0.0.0/post";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
Expand Down Expand Up @@ -437,7 +437,7 @@ - (void)testTaskTimeOut {
config.timeoutIntervalForRequest = 5;
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];

NSString *urlString = @"http://httpbin.org/delay/10";
NSString *urlString = @"http://0.0.0.0/delay/10";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.timeoutInterval = 5;
Expand All @@ -459,7 +459,7 @@ - (void)testConcurrentRequests {
dispatch_group_t gourp = dispatch_group_create();
for (int i = 0; i < 10; i++) {
dispatch_group_enter(gourp);
NSString *urlString = [NSString stringWithFormat:@"http://httpbin.org/get?capital=testDataTaskWithURL%@", @(i)];
NSString *urlString = [NSString stringWithFormat:@"http://0.0.0.0/get?capital=testDataTaskWithURL%@", @(i)];
NSURL *url = [NSURL URLWithString:urlString];
XCTestExpectation *te = [self
expectationWithDescription:[NSString
Expand All @@ -483,7 +483,7 @@ - (void)testOutOfRangeButCorrectlyFormattedHTTPCode {
config.timeoutIntervalForRequest = 8;
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];

NSString *urlString = @"http://httpbin.org/status/999";
NSString *urlString = @"http://0.0.0.0/status/999";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *req = [NSURLRequest requestWithURL:url];

Expand All @@ -508,7 +508,7 @@ - (void)testMissingContentLengthButStillABody {
config.timeoutIntervalForRequest = 8;
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];

NSString *urlString = @"https://httpbin.org/stream-bytes/10";
NSString *urlString = @"http://0.0.0.0/stream-bytes/10";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *req = [NSURLRequest requestWithURL:url];

Expand All @@ -534,7 +534,7 @@ - (void)testSimpleUploadWithDelegate {

delegate.uploadCompletedExpectation = [self expectationWithDescription:@"PUT testSimpleUploadWithDelegate"];

NSString *urlString = @"https://httpbin.org/put";
NSString *urlString = @"http://0.0.0.0/put";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
req.HTTPMethod = @"PUT";
Expand All @@ -549,7 +549,7 @@ - (void)testSimpleUploadWithDelegate {
- (void)testRequestWithEmptyBody {
NSArray *httpMethods = @[ @"GET", @"PUT", @"POST", @"DELETE" ];
for (NSString *method in httpMethods) {
NSString *urlString = [NSString stringWithFormat:@"https://httpbin.org/%@", [method lowercaseString]];
NSString *urlString = [NSString stringWithFormat:@"http://0.0.0.0/%@", [method lowercaseString]];
for (id body in @[ [NSNull null], [NSData data] ]) {
for (id contentType in @[ @"text/plain; charset=utf-8", [NSNull null] ]) {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
Expand Down Expand Up @@ -606,7 +606,7 @@ - (void)testRequestWithNonEmptyBody {
NSArray *httpMethods = @[ @"GET", @"PUT", @"POST", @"DELETE" ];
for (NSString *method in httpMethods) {
NSData *bodyData = [@"This is a request body" dataUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = [NSString stringWithFormat:@"https://httpbin.org/%@", [method lowercaseString]];
NSString *urlString = [NSString stringWithFormat:@"http://0.0.0.0/%@", [method lowercaseString]];
for (id contentType in @[ @"text/plain; charset=utf-8", [NSNull null] ]) {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
request.HTTPMethod = method;
Expand Down Expand Up @@ -683,7 +683,7 @@ - (void)testSimpleUploadWithDelegateProvidingInputStream {
completionHandler([[NSInputStream alloc] initWithData:data]);
};

NSString *urlString = [NSString stringWithFormat:@"http://httpbin.org/%@", [method lowercaseString]];
NSString *urlString = [NSString stringWithFormat:@"http://0.0.0.0/%@", [method lowercaseString]];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
req.HTTPMethod = method;
Expand Down Expand Up @@ -769,8 +769,7 @@ - (void)testDisableCookiesStorage {
XCTAssertEqual(config.HTTPCookieStorage.cookies.count, 0);

YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];
NSString *urlString =
@"https://httpbin.org/response-headers?Set-Cookie=a=bbbb&Set-Cookie=a=bbbb1&Set-Cookie=b=bbbb2";
NSString *urlString = @"http://0.0.0.0/response-headers?Set-Cookie=a=bbbb&Set-Cookie=a=bbbb1&Set-Cookie=b=bbbb2";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
req.HTTPMethod = @"POST";
Expand Down Expand Up @@ -800,7 +799,7 @@ - (void)testCookiesStorage {

YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];
NSString *urlString =
@"https://httpbin.org/"
@"http://0.0.0.0/"
@"response-headers?Set-Cookie=a=bbbb&Set-Cookie=a=bbbb1&Set-Cookie=b=bbbb2&Set-Cookie=b=bbbb2";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
Expand Down Expand Up @@ -834,7 +833,7 @@ - (void)testPreviouslySetCookiesAreSentInLaterRequests {

YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];
NSString *urlString =
@"https://httpbin.org/"
@"http://0.0.0.0/"
@"response-headers?Set-Cookie=a=bbbb&Set-Cookie=a=bbbb1&Set-Cookie=b=bbbb2&Set-Cookie=b=bbbb2";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
Expand All @@ -850,7 +849,7 @@ - (void)testPreviouslySetCookiesAreSentInLaterRequests {
XCTAssertNotNil(httpresponse.allHeaderFields[@"Set-Cookie"]);
XCTAssertEqual([NSHTTPCookieStorage sharedHTTPCookieStorage].cookies.count, 2);

task2 = [session taskWithURL:[NSURL URLWithString:@"https://httpbin.org/cookies"]
task2 = [session taskWithURL:[NSURL URLWithString:@"http://0.0.0.0/cookies"]
completionHandler:^(
NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
XCTAssertNotNil(data);
Expand All @@ -872,7 +871,7 @@ - (void)testPreviouslySetCookiesAreSentInLaterRequests {
}

//- (void)testBasicAuthRequest {
// NSString *urlString = @"https://httpbin.org/basic-auth/zymxxxs/zymxxxs";
// NSString *urlString = @"http://0.0.0.0/basic-auth/zymxxxs/zymxxxs";
// NSURL *url = [NSURL URLWithString:urlString];
// XCTestExpectation *te = [self expectationWithDescription:@"GET testBasicAuthRequest: with a delegate"];
// YMDataTask *d = [[YMDataTask alloc] initWithExpectation:te];
Expand All @@ -887,7 +886,7 @@ - (void)testPostWithEmptyBody {
config.timeoutIntervalForRequest = 5;
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];

NSString *urlString = @"https://httpbin.org/post";
NSString *urlString = @"http://0.0.0.0/post";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
req.HTTPMethod = @"POST";
Expand All @@ -909,7 +908,7 @@ - (void)testCheckErrorTypeAfterInvalidateAndCancel {
XCTestExpectation *expectation =
[self expectationWithDescription:@"Check error code of tasks after invalidateAndCancel"];

NSString *urlString = @"http://httpbin.org/delay/5";
NSString *urlString = @"http://0.0.0.0/delay/5";
NSURL *url = [NSURL URLWithString:urlString];
YMSessionDelegate *delegate = [YMSessionDelegate new];
YMURLSessionConfiguration *config = [YMURLSessionConfiguration defaultSessionConfiguration];
Expand All @@ -931,9 +930,9 @@ - (void)testTaskCountAfterInvalidateAndCancel {

YMURLSessionConfiguration *config = [YMURLSessionConfiguration defaultSessionConfiguration];
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];
NSURL *url1 = [NSURL URLWithString:@"http://httpbin.org/delay/5"];
NSURL *url2 = [NSURL URLWithString:@"http://httpbin.org/delay/15"];
NSURL *url3 = [NSURL URLWithString:@"http://httpbin.org/delay/25"];
NSURL *url1 = [NSURL URLWithString:@"http://0.0.0.0/delay/5"];
NSURL *url2 = [NSURL URLWithString:@"http://0.0.0.0/delay/15"];
NSURL *url3 = [NSURL URLWithString:@"http://0.0.0.0/delay/25"];

YMURLSessionTask *task1 = [session taskWithURL:url1];
YMURLSessionTask *task2 = [session taskWithURL:url2];
Expand Down Expand Up @@ -971,9 +970,9 @@ - (void)testGetAllTasks {

YMURLSessionConfiguration *config = [YMURLSessionConfiguration defaultSessionConfiguration];
YMURLSession *session = [YMURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];
NSURL *url1 = [NSURL URLWithString:@"https://httpbin.org/delay/5"];
NSURL *url2 = [NSURL URLWithString:@"https://httpbin.org/delay/10"];
NSURL *url3 = [NSURL URLWithString:@"https://httpbin.org/delay/15"];
NSURL *url1 = [NSURL URLWithString:@"http://0.0.0.0/delay/5"];
NSURL *url2 = [NSURL URLWithString:@"http://0.0.0.0/delay/10"];
NSURL *url3 = [NSURL URLWithString:@"http://0.0.0.0/delay/15"];

YMURLSessionTask *task1 = [session taskWithURL:url1];
YMURLSessionTask *task2 = [session taskWithURL:url2];
Expand Down Expand Up @@ -1040,7 +1039,7 @@ - (void)testNoDoubleCallbackWhenCancellingAndProtocolFailsFast {
}

- (void)testCancelledTasksCannotBeResumed {
NSString *urlString = @"http://httpbin.org/delay/5";
NSString *urlString = @"http://0.0.0.0/delay/5";
NSURL *url = [NSURL URLWithString:urlString];
YMSessionDelegate *delegate = [YMSessionDelegate new];
YMURLSessionConfiguration *config = [YMURLSessionConfiguration defaultSessionConfiguration];
Expand All @@ -1060,7 +1059,7 @@ - (void)testCancelledTasksCannotBeResumed {
- (void)testSuspendResumeTask {
XCTestExpectation *expectation = [self expectationWithDescription:@"GET testSuspendResumeTask: suspend task"];
YMURLSessionTask *task = [[YMURLSession sharedSession]
taskWithURL:[NSURL URLWithString:@"https://httpbin.org/get"]
taskWithURL:[NSURL URLWithString:@"http://0.0.0.0/get"]
completionHandler:^(NSData *_Nullable data, NSHTTPURLResponse *_Nullable response, NSError *_Nullable error) {
if (response.statusCode == 200) {
[expectation fulfill];
Expand Down
Loading