diff --git a/.github/workflows/sast-scan.yml b/.github/workflows/sast-scan.yml deleted file mode 100644 index f931630..0000000 --- a/.github/workflows/sast-scan.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: SAST Scan -on: - pull_request: - types: [opened, synchronize, reopened] -jobs: - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Horusec Scan - run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/src horuszup/horusec-cli:latest horusec start -p /src -P $(pwd) \ No newline at end of file diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml new file mode 100644 index 0000000..f1d6cf0 --- /dev/null +++ b/.github/workflows/sca-scan.yml @@ -0,0 +1,13 @@ +name: Source Composition Analysis Scan +on: + pull_request: + types: [opened, synchronize, reopened] +jobs: + security: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Run Snyk to check for vulnerabilities + uses: snyk/actions/cocoapods@master + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} diff --git a/.github/workflows/secrets-scan.yml b/.github/workflows/secrets-scan.yml deleted file mode 100644 index 1e8f176..0000000 --- a/.github/workflows/secrets-scan.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Secrets Scan -on: - pull_request: - types: [opened, synchronize, reopened] -jobs: - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Gittyleaks - uses: gupy-io/gittyleaks-action@v0.1 \ No newline at end of file diff --git a/Contentstack.podspec b/Contentstack.podspec index 373b6df..823553b 100644 --- a/Contentstack.podspec +++ b/Contentstack.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Contentstack' -s.version = '3.12.0' +s.version = '3.12.1' s.summary = 'Contentstack is a headless CMS with an API-first approach that puts content at the centre.' s.description = <<-DESC @@ -12,7 +12,7 @@ s.homepage = 'https://www.contentstack.com/' s.license = { :type => 'Commercial',:text => 'See https://www.contentstack.com/'} s.author = { 'Contentstack' => 'support@contentstack.io' } -s.source = { :git => 'https://github.com/contentstack/contentstack-ios.git', :tag => 'v3.12.0' } +s.source = { :git => 'https://github.com/contentstack/contentstack-ios.git', :tag => 'v3.12.1' } s.social_media_url = 'https://twitter.com/Contentstack' s.ios.deployment_target = '11.0' diff --git a/ContentstackInternal/CSIOCoreHTTPNetworking.m b/ContentstackInternal/CSIOCoreHTTPNetworking.m index 464724f..6b2650c 100644 --- a/ContentstackInternal/CSIOCoreHTTPNetworking.m +++ b/ContentstackInternal/CSIOCoreHTTPNetworking.m @@ -299,7 +299,7 @@ - (NSMutableURLRequest *)urlRequestForStack:(Stack*)stack [additionalHeaders enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { [request setValue:obj forHTTPHeaderField:key]; }]; - + NSString *userAgent = [self userAgent]; NSString *version = sdkVersion; [request setValue:[NSString stringWithFormat:@"contentstack-ios/%@",version] forHTTPHeaderField:@"X-User-Agent"]; @@ -337,7 +337,6 @@ - (NSURLSessionDataTask*)requestForStack:(Stack*)stack urlString = [NSString stringWithFormat:@"%@://%@%@", [self protocolStringForSSL], stack.hostURL, urlPath]; } // Cache handler - ResponseType resType = NETWORK; // switch (cachePolicy) { // case NETWORK_ONLY: // [self.httpSessionManager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; @@ -370,19 +369,7 @@ - (NSURLSessionDataTask*)requestForStack:(Stack*)stack // Initiate request NSMutableURLRequest *mutableRequest = [self urlRequestForStack:stack withURLPath:urlString requestType:requestType params:paramDict additionalHeaders:additionalHeaders]; mutableRequest.HTTPMethod = @"GET"; - - NSURLSessionDataTask *task = [self.urlSessionManager dataTaskWithRequest:mutableRequest success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) { - if ((cachePolicy != NETWORK_ONLY || cachePolicy != CACHE_THEN_NETWORK) && responseObject != nil) { - [self saveToCacheDataTask:task responseObject:responseObject]; - } - completionBlock(resType, responseObject, nil); - } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) { - if (cachePolicy == NETWORK_ELSE_CACHE) { - [self fullfillRequestWithCache:task.originalRequest completion:completionBlock]; - } else { - completionBlock(resType, task.response, error); - } - }]; + // NSURLSessionDataTask *task = [self.httpSessionManager GET:urlString parameters:paramDict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { // if (cachePolicy != NETWORK_ONLY || cachePolicy != CACHE_THEN_NETWORK) { // [self saveToCacheDataTask:task responseObject:responseObject]; @@ -407,6 +394,45 @@ - (NSURLSessionDataTask*)requestForStack:(Stack*)stack // [self fullfillRequestWithCache:task.originalRequest completion:completionBlock]; // [task suspend]; // } + return [self performRequest: mutableRequest cachePolicy:cachePolicy completion:completionBlock]; +} + +- (NSURLSessionDataTask*) performRequest:(NSMutableURLRequest*) mutableRequest + cachePolicy:(CachePolicy)cachePolicy + completion:(CSIONetworkCompletionHandler)completionBlock{ + ResponseType resType = NETWORK; + NSString *retryCount = mutableRequest.allHTTPHeaderFields[@"x-cs-retry-count"]; + if (retryCount) { + int retryInt = [retryCount intValue];// I assume you need it as an integer. + [mutableRequest setValue:[NSString stringWithFormat:@"%d",(++retryInt)] forHTTPHeaderField:@"x-cs-retry-count"]; + }else { + [mutableRequest setValue:@"0" forHTTPHeaderField:@"x-cs-retry-count"]; + } + + __weak typeof (self) weakSelf = self; + + NSURLSessionDataTask *task = [self.urlSessionManager dataTaskWithRequest:mutableRequest success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) { + if (cachePolicy != NETWORK_ONLY && responseObject != nil) { + [self saveToCacheDataTask:task responseObject:responseObject]; + } + + completionBlock(resType, responseObject, nil); + } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) { + if (cachePolicy == NETWORK_ELSE_CACHE) { + [self fullfillRequestWithCache:task.originalRequest completion:completionBlock]; + } else { + NSString *retryCount = task.originalRequest.allHTTPHeaderFields[@"x-cs-retry-count"]; + int currentRetryCount = [retryCount intValue]; + + if ((error.code == 408 || error.code == 429 )&& currentRetryCount < 5) { + NSTimeInterval timeInterval = pow(2, ++currentRetryCount) * 100 / 1000; + [NSThread sleepForTimeInterval:timeInterval]; + [weakSelf performRequest:task.originalRequest.mutableCopy cachePolicy:cachePolicy completion:completionBlock]; + }else { + completionBlock(resType, task.response, error); + } + } + }]; return task; } diff --git a/Podfile.lock b/Podfile.lock index fd3b0f4..8035a50 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,3 +1,3 @@ PODFILE CHECKSUM: e70b33906e829ccd2b052bc0e0cff91ee8ee49e6 -COCOAPODS: 1.11.3 +COCOAPODS: 1.13.0