From f749efdd0af3b9d9058bebb34b9de6ba8a490e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Tue, 4 Sep 2018 19:42:09 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E5=B0=86=E5=90=8C=E6=AD=A5=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E6=97=B6=E9=97=B4=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E6=94=BE=E5=88=B0=E9=87=8D=E8=AF=95=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E6=AD=A3=E5=B8=B8=E8=AF=B7=E6=B1=82=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E8=B5=B0=E5=90=8C=E6=AD=A5=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91=E3=80=82=E4=BB=A5=E9=98=B2=E9=80=9A?= =?UTF-8?q?=E8=BF=87cdn=E8=BF=94=E5=9B=9E=E7=9A=84Date=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=88=B0=E9=94=99=E8=AF=AF=E7=9A=84=E7=BC=93=E5=AD=98=E6=97=B6?= =?UTF-8?q?=E9=97=B4=EF=BC=8C=E5=AF=BC=E8=87=B4=E7=94=9F=E6=88=90=E7=9A=84?= =?UTF-8?q?=E7=AD=BE=E5=90=8Durl=E6=9C=89=E5=8F=AF=E8=83=BD=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSNetworking.m | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/AliyunOSSSDK/OSSNetworking.m b/AliyunOSSSDK/OSSNetworking.m index b773817c..f74b03bb 100644 --- a/AliyunOSSSDK/OSSNetworking.m +++ b/AliyunOSSSDK/OSSNetworking.m @@ -282,19 +282,6 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)sessionTask return ; } - //Correct Clock Skew - NSString * dateStr = [[httpResponse allHeaderFields] objectForKey:@"Date"]; - if ([dateStr length] > 0) { - NSDate * serverTime = [NSDate oss_dateFromString:dateStr]; - NSDate * deviceTime = [NSDate date]; - NSTimeInterval skewTime = [deviceTime timeIntervalSinceDate:serverTime]; - [NSDate oss_setClockSkew:skewTime]; - } else if (!error) { - // The response header does not have the 'Date' field. - // This should not happen. - OSSLogError(@"Date header does not exist, unable to fix the clock skew"); - } - /* background upload task will not call back didRecieveResponse */ if (delegate.isBackgroundUploadFileTask) { OSSLogVerbose(@"backgroud upload task did recieve response: %@", httpResponse); @@ -359,6 +346,18 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)sessionTask case OSSNetworkingRetryTypeShouldCorrectClockSkewAndRetry: { /* correct clock skew */ + NSString * dateStr = [[httpResponse allHeaderFields] objectForKey:@"Date"]; + if ([dateStr length] > 0) { + NSDate * serverTime = [NSDate oss_dateFromString:dateStr]; + NSDate * deviceTime = [NSDate date]; + NSTimeInterval skewTime = [deviceTime timeIntervalSinceDate:serverTime]; + [NSDate oss_setClockSkew:skewTime]; + } else if (!error) { + // The response header does not have the 'Date' field. + // This should not happen. + OSSLogError(@"Date header does not exist, unable to fix the clock skew"); + } + [delegate.interceptors insertObject:[OSSTimeSkewedFixingInterceptor new] atIndex:0]; break; } From 2952f11798685760031ad63c3f2390e4554f8989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Wed, 5 Sep 2018 17:05:45 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9isCancelled=E4=B8=BA?= =?UTF-8?q?=E5=8E=9F=E5=AD=90=E5=B1=9E=E6=80=A7=EF=BC=8C=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E8=AF=BB=E5=86=99=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSRequest.h | 2 +- AliyunOSSSDK/OSSRequest.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AliyunOSSSDK/OSSRequest.h b/AliyunOSSSDK/OSSRequest.h index de9329a0..35bd547a 100644 --- a/AliyunOSSSDK/OSSRequest.h +++ b/AliyunOSSSDK/OSSRequest.h @@ -21,7 +21,7 @@ /** the flag of request canceled. */ -@property (nonatomic, assign) BOOL isCancelled; +@property (atomic, assign) BOOL isCancelled; /** the flag of verification about crc64 diff --git a/AliyunOSSSDK/OSSRequest.m b/AliyunOSSSDK/OSSRequest.m index b6e736be..75850b56 100644 --- a/AliyunOSSSDK/OSSRequest.m +++ b/AliyunOSSSDK/OSSRequest.m @@ -27,7 +27,7 @@ - (instancetype)init { } - (void)cancel { - _isCancelled = YES; + self.isCancelled = YES; if (self.requestDelegate) { [self.requestDelegate cancel]; From 07d580b399b9bc1f984303eaf1f8a9237703ef75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Wed, 5 Sep 2018 19:34:42 +0800 Subject: [PATCH 03/14] =?UTF-8?q?listParts=E6=8E=A5=E5=8F=A3=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=95=B0=E6=8D=AE=E8=A7=A3=E6=9E=90=EF=BC=8C=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AF=E6=96=B0=E5=A2=9E=E4=BA=86hashcode=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=EF=BC=8C=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSClient.m | 43 ++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/AliyunOSSSDK/OSSClient.m b/AliyunOSSSDK/OSSClient.m index 6d9da327..b641f45f 100644 --- a/AliyunOSSSDK/OSSClient.m +++ b/AliyunOSSSDK/OSSClient.m @@ -1541,35 +1541,44 @@ - (OSSTask *)multipartUpload:(OSSMultipartUploadRequest *)request resumable:(BOO } [uploadedPart enumerateObjectsUsingBlock:^(NSDictionary *partInfo, NSUInteger idx, BOOL * _Nonnull stop) { - unsigned long long iPartNum = 0; - NSString *partNumberString = [partInfo objectForKey:OSSPartNumberXMLTOKEN]; - NSScanner *scanner = [NSScanner scannerWithString:partNumberString]; - [scanner scanUnsignedLongLong:&iPartNum]; + unsigned long long remotePartNumber = 0; + NSString *partNumberString = [partInfo objectForKey: OSSPartNumberXMLTOKEN]; + NSScanner *scanner = [NSScanner scannerWithString: partNumberString]; + [scanner scanUnsignedLongLong: &remotePartNumber]; - unsigned long long iPartSize = 0; + unsigned long long remotePartHashCode = 0; + NSString *hashCode = [partInfo objectForKey:OSSPartHashCodeXMLTOKEN]; + scanner = [NSScanner scannerWithString:hashCode]; + [scanner scanUnsignedLongLong:&remotePartHashCode]; + + NSString *remotePartEtag = [partInfo objectForKey:OSSETagXMLTOKEN]; + + unsigned long long remotePartSize = 0; NSString *partSizeString = [partInfo objectForKey:OSSSizeXMLTOKEN]; scanner = [NSScanner scannerWithString:partSizeString]; - [scanner scanUnsignedLongLong:&iPartSize]; - - NSString *eTag = [partInfo objectForKey:OSSETagXMLTOKEN]; + [scanner scanUnsignedLongLong:&remotePartSize]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wshorten-64-to-32" - OSSPartInfo * info = [OSSPartInfo partInfoWithPartNum:iPartNum - eTag:eTag - size:iPartSize - crc64:0]; + OSSPartInfo * info = [[OSSPartInfo alloc] init]; + info.partNum = remotePartNumber; + info.size = remotePartSize; + info.crc64 = remotePartHashCode; + info.eTag = remotePartEtag; + #pragma clang diagnostic pop - NSDictionary *tPartInfo = [localPartInfos objectForKey:[NSString stringWithFormat:@"%llu",iPartNum]]; - if (tPartInfo) - { - info.crc64 = [tPartInfo[@"crc64"] unsignedLongLongValue]; + if (!hashCode) { + NSDictionary *tPartInfo = [localPartInfos objectForKey:[NSString stringWithFormat:@"%llu",remotePartNumber]]; + if (tPartInfo[@"crc64"]) + { + info.crc64 = [tPartInfo[@"crc64"] unsignedLongLongValue]; + } } [uploadedPartInfos addObject:info]; - [alreadyUploadIndex addObject:@(info.partNum)]; + [alreadyUploadIndex addObject:@(remotePartNumber)]; }]; if ([alreadyUploadIndex count] > 0 && request.uploadProgress && uploadFileSize) { From 00eda08c0503b45549664dea5c0bfa6c366c2726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Wed, 5 Sep 2018 19:36:02 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E9=9C=80=E8=A6=81=E8=B0=83=E7=94=A8initM?= =?UTF-8?q?ultipartUpload=E6=8E=A5=E5=8F=A3=E8=8E=B7=E5=8F=96uploadId?= =?UTF-8?q?=E5=90=8E=E5=88=9D=E5=A7=8B=E5=8C=96localPartInfosPath=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSClient.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AliyunOSSSDK/OSSClient.m b/AliyunOSSSDK/OSSClient.m index b641f45f..1b25c3b8 100644 --- a/AliyunOSSSDK/OSSClient.m +++ b/AliyunOSSSDK/OSSClient.m @@ -1606,6 +1606,8 @@ - (OSSTask *)multipartUpload:(OSSMultipartUploadRequest *)request resumable:(BOO } request.uploadId = uploadId; + localPartInfosPath = [[[NSString oss_documentDirectory] stringByAppendingPathComponent:oss_partInfos_storage_name] stringByAppendingPathComponent:uploadId]; + if (request.isCancelled) { if(resumable) From 8dfd6d7ea43139ff3a9b55383d61fa6f8d3a759a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Wed, 5 Sep 2018 19:55:51 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=97=B6=E5=87=BA=E7=8E=B0=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=9F=90=E4=B8=AA=E5=88=86=E7=89=87=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=9C=80=E7=BB=88=E4=B8=8A=E4=BC=A0=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSClient.m | 146 +++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/AliyunOSSSDK/OSSClient.m b/AliyunOSSSDK/OSSClient.m index 1b25c3b8..1c0786c7 100644 --- a/AliyunOSSSDK/OSSClient.m +++ b/AliyunOSSSDK/OSSClient.m @@ -1696,7 +1696,6 @@ - (OSSTask *)sequentialUpload:(OSSMultipartUploadRequest *)request fileSize:(unsigned long long)uploadFileSize { OSSRequestCRCFlag crcFlag = request.crcFlag; - __block BOOL isCancel = NO; __block OSSTask *errorTask; __block NSMutableDictionary *localPartInfos = nil; @@ -1714,94 +1713,95 @@ - (OSSTask *)sequentialUpload:(OSSMultipartUploadRequest *)request return [OSSTask taskWithError: readError]; } - NSData * uploadPartData; NSUInteger realPartLength = request.partSize; for (int i = 1; i <= partCout; i++) { - realPartLength = request.partSize; - if (isCancel && errorTask != nil) { - if (errorTask == nil) { - errorTask = [OSSTask taskWithError:[OSSClient cancelError]]; - } + if (errorTask) { break; } + + if (request.isCancelled) { + errorTask = [OSSTask taskWithError:[OSSClient cancelError]]; + break; + } + + if ([alreadyUploadIndex containsObject:@(i)]) { + continue; + } + realPartLength = request.partSize; - @autoreleasepool{ - //alreadyUploadIndex 为空 return false - if (alreadyUploadIndex && [alreadyUploadIndex containsObject:@(i)]) { - continue; - } - [fileHande seekToFileOffset:request.partSize * (i - 1)]; - if (i == partCout) { + [fileHande seekToFileOffset:request.partSize * (i - 1)]; + if (i == partCout) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wshorten-64-to-32" - realPartLength = uploadFileSize - request.partSize * (i - 1); + realPartLength = uploadFileSize - request.partSize * (i - 1); #pragma clang diagnostic pop - } - uploadPartData = [fileHande readDataOfLength:realPartLength]; + } + NSData *uploadPartData = [fileHande readDataOfLength:realPartLength]; + + @autoreleasepool { + OSSUploadPartRequest * uploadPart = [OSSUploadPartRequest new]; + uploadPart.bucketName = request.bucketName; + uploadPart.objectkey = request.objectKey; + uploadPart.partNumber = i; + uploadPart.uploadId = request.uploadId; + uploadPart.uploadPartData = uploadPartData; + uploadPart.contentMd5 = [OSSUtil base64Md5ForData:uploadPartData]; + uploadPart.crcFlag = request.crcFlag; - if (request.isCancelled) { - @synchronized(lock){ - if(!isCancel){ - isCancel = YES; - } + OSSTask * uploadPartTask = [self uploadPart:uploadPart]; + [uploadPartTask waitUntilFinished]; + + if (uploadPartTask.error) { + if (uploadPartTask.error.code != -409) { + errorTask = uploadPartTask; + break; + } else { + NSDictionary *partDict = uploadPartTask.error.userInfo; + OSSPartInfo *partInfo = [[OSSPartInfo alloc] init]; + partInfo.eTag = partDict[@"PartEtag"]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wshorten-64-to-32" + partInfo.partNum = [(NSString *)partDict[@"PartNumber"] integerValue]; + partInfo.size = realPartLength; +#pragma clang diagnostic push + partInfo.crc64 = [[uploadPartData mutableCopy] oss_crc64]; + + [alreadyUploadPart addObject:partInfo]; } } else { - OSSUploadPartRequest * uploadPart = [OSSUploadPartRequest new]; - uploadPart.bucketName = request.bucketName; - uploadPart.objectkey = request.objectKey; - uploadPart.partNumber = i; - uploadPart.uploadId = request.uploadId; - uploadPart.uploadPartData = uploadPartData; - uploadPart.contentMd5 = [OSSUtil base64Md5ForData:uploadPartData]; - uploadPart.crcFlag = request.crcFlag; + OSSUploadPartResult * result = uploadPartTask.result; + OSSPartInfo * partInfo = [OSSPartInfo new]; + partInfo.partNum = i; + partInfo.eTag = result.eTag; + partInfo.size = realPartLength; + uint64_t crc64OfPart; + @try { + NSScanner *scanner = [NSScanner scannerWithString:result.remoteCRC64ecma]; + [scanner scanUnsignedLongLong:&crc64OfPart]; + partInfo.crc64 = crc64OfPart; + } @catch (NSException *exception) { + OSSLogError(@"multipart upload error with nil remote crc64!"); + } - OSSTask * uploadPartTask = [self uploadPart:uploadPart]; - [uploadPartTask waitUntilFinished]; - if (uploadPartTask.error) { - if (uploadPartTask.error.code != -409) { - errorTask = uploadPartTask; - break; - } - } else { - OSSUploadPartResult * result = uploadPartTask.result; - OSSPartInfo * partInfo = [OSSPartInfo new]; - partInfo.partNum = i; - partInfo.eTag = result.eTag; - partInfo.size = realPartLength; - uint64_t crc64OfPart; - @try { - NSScanner *scanner = [NSScanner scannerWithString:result.remoteCRC64ecma]; - [scanner scanUnsignedLongLong:&crc64OfPart]; - partInfo.crc64 = crc64OfPart; - } @catch (NSException *exception) { - OSSLogError(@"multipart upload error with nil remote crc64!"); - } - - @synchronized(lock){ - - [alreadyUploadPart addObject:partInfo]; - - if (crcFlag == OSSRequestCRCOpen) - { - [self processForLocalPartInfos:localPartInfos - partInfo:partInfo - uploadId:request.uploadId]; - [self persistencePartInfos:localPartInfos - withUploadId:request.uploadId]; - } - *uploadedLength += realPartLength; - if (request.uploadProgress) - { - request.uploadProgress(realPartLength, *uploadedLength, uploadFileSize); - } + [alreadyUploadPart addObject:partInfo]; + if (crcFlag == OSSRequestCRCOpen) + { + [self processForLocalPartInfos:localPartInfos + partInfo:partInfo + uploadId:request.uploadId]; + [self persistencePartInfos:localPartInfos + withUploadId:request.uploadId]; + } + + @synchronized(lock) { + *uploadedLength += realPartLength; + if (request.uploadProgress) + { + request.uploadProgress(realPartLength, *uploadedLength, uploadFileSize); } } } - if (isCancel) { - errorTask = [OSSTask taskWithError:[OSSClient cancelError]]; - break; - } } } [fileHande closeFile]; From 9fa1c6167cc52f7f432aae66a0541bc1c7489412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Thu, 6 Sep 2018 16:06:44 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E5=9C=A8listParts?= =?UTF-8?q?=E6=97=B6=E6=96=B0=E5=A2=9E=E8=BF=94=E5=9B=9Epart=20crc64=20cod?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSDefine.h | 1 + 1 file changed, 1 insertion(+) diff --git a/AliyunOSSSDK/OSSDefine.h b/AliyunOSSSDK/OSSDefine.h index 324c3a42..dbe8f8a3 100644 --- a/AliyunOSSSDK/OSSDefine.h +++ b/AliyunOSSSDK/OSSDefine.h @@ -54,6 +54,7 @@ #define OSSMaxPartsXMLTOKEN @"MaxParts" #define OSSPartXMLTOKEN @"Part" #define OSSPartNumberXMLTOKEN @"PartNumber" +#define OSSPartHashCodeXMLTOKEN @"HashCrc64ecma" #define OSSClientErrorDomain @"com.aliyun.oss.clientError" #define OSSServerErrorDomain @"com.aliyun.oss.serverError" From a87bb1f8e8318ccd7e766e98279b3796647d7ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Fri, 7 Sep 2018 17:52:18 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9buildCanonicalURL?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSNetworkingRequestDelegate.m | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/AliyunOSSSDK/OSSNetworkingRequestDelegate.m b/AliyunOSSSDK/OSSNetworkingRequestDelegate.m index 323e6965..e80293ff 100644 --- a/AliyunOSSSDK/OSSNetworkingRequestDelegate.m +++ b/AliyunOSSSDK/OSSNetworkingRequestDelegate.m @@ -76,21 +76,24 @@ - (OSSTask *)buildInternalHttpRequest { // build base url string NSString * urlString = self.allNeededMessage.endpoint; - NSURL * endPointURL = [NSURL URLWithString:self.allNeededMessage.endpoint]; + NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:urlString]; + if (self.allNeededMessage.bucketName) { OSSIPv6Adapter *ipv6Adapter = [OSSIPv6Adapter getInstance]; - if ([OSSUtil isOssOriginBucketHost:endPointURL.host]) { - urlString = [NSString stringWithFormat:@"%@://%@.%@", endPointURL.scheme, self.allNeededMessage.bucketName, endPointURL.host]; - } else if ([ipv6Adapter isIPv4Address: endPointURL.host] || [ipv6Adapter isIPv6Address: endPointURL.host]) { - urlString = [NSString stringWithFormat:@"%@://%@/%@/", endPointURL.scheme, endPointURL.host, self.allNeededMessage.bucketName]; + if ([OSSUtil isOssOriginBucketHost:urlComponents.host]) { + // eg. insert bucket to the begining of host. + urlComponents.host = [NSString stringWithFormat:@"%@.%@", self.allNeededMessage.bucketName, urlComponents.host]; + urlString = urlComponents.URL.absoluteString; + } else if ([ipv6Adapter isIPv4Address: urlComponents.host] || [ipv6Adapter isIPv6Address: urlComponents.host]) { + urlString = [urlString stringByAppendingFormat:@"/%@/", self.allNeededMessage.bucketName]; } } - endPointURL = [NSURL URLWithString:urlString]; - NSString * urlHost = endPointURL.host; + urlComponents = [[NSURLComponents alloc] initWithString:urlString]; + NSString * urlHost = urlComponents.host; if (!self.isAccessViaProxy && [OSSUtil isOssOriginBucketHost:urlHost] && self.isHttpdnsEnable) { NSString * httpdnsResolvedResult = [OSSUtil getIpByHost:urlHost]; - urlString = [NSString stringWithFormat:@"%@://%@", endPointURL.scheme, httpdnsResolvedResult]; + urlString = [NSString stringWithFormat:@"%@://%@", urlComponents.scheme, httpdnsResolvedResult]; } if (self.allNeededMessage.objectKey) { From 660c51aa98b03634beb6df8e2d0320805f8c0217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Tue, 11 Sep 2018 16:33:33 +0800 Subject: [PATCH 08/14] =?UTF-8?q?409=E9=94=99=E8=AF=AF=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSClient.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AliyunOSSSDK/OSSClient.m b/AliyunOSSSDK/OSSClient.m index 1c0786c7..5d9668ce 100644 --- a/AliyunOSSSDK/OSSClient.m +++ b/AliyunOSSSDK/OSSClient.m @@ -1406,7 +1406,7 @@ - (void)executePartUpload:(OSSMultipartUploadRequest *)request totalBytesExpecte OSSTask * uploadPartTask = [self uploadPart:uploadPart]; [uploadPartTask waitUntilFinished]; if (uploadPartTask.error) { - if (uploadPartTask.error.code != -409) { + if (abs(uploadPartTask.error.code) != 409) { *errorTask = uploadPartTask; } } else { @@ -1753,7 +1753,7 @@ - (OSSTask *)sequentialUpload:(OSSMultipartUploadRequest *)request [uploadPartTask waitUntilFinished]; if (uploadPartTask.error) { - if (uploadPartTask.error.code != -409) { + if (abs(uploadPartTask.error.code) != 409) { errorTask = uploadPartTask; break; } else { From ece079d5351848807beb148c08c9ab14778172b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Tue, 11 Sep 2018 16:35:20 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSClient.m | 17 +++-------------- AliyunOSSSDK/OSSDefine.h | 1 - 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/AliyunOSSSDK/OSSClient.m b/AliyunOSSSDK/OSSClient.m index 5d9668ce..6fd4f73f 100644 --- a/AliyunOSSSDK/OSSClient.m +++ b/AliyunOSSSDK/OSSClient.m @@ -1546,11 +1546,6 @@ - (OSSTask *)multipartUpload:(OSSMultipartUploadRequest *)request resumable:(BOO NSScanner *scanner = [NSScanner scannerWithString: partNumberString]; [scanner scanUnsignedLongLong: &remotePartNumber]; - unsigned long long remotePartHashCode = 0; - NSString *hashCode = [partInfo objectForKey:OSSPartHashCodeXMLTOKEN]; - scanner = [NSScanner scannerWithString:hashCode]; - [scanner scanUnsignedLongLong:&remotePartHashCode]; - NSString *remotePartEtag = [partInfo objectForKey:OSSETagXMLTOKEN]; unsigned long long remotePartSize = 0; @@ -1564,18 +1559,12 @@ - (OSSTask *)multipartUpload:(OSSMultipartUploadRequest *)request resumable:(BOO OSSPartInfo * info = [[OSSPartInfo alloc] init]; info.partNum = remotePartNumber; info.size = remotePartSize; - info.crc64 = remotePartHashCode; info.eTag = remotePartEtag; #pragma clang diagnostic pop - - if (!hashCode) { - NSDictionary *tPartInfo = [localPartInfos objectForKey:[NSString stringWithFormat:@"%llu",remotePartNumber]]; - if (tPartInfo[@"crc64"]) - { - info.crc64 = [tPartInfo[@"crc64"] unsignedLongLongValue]; - } - } + + NSDictionary *tPartInfo = [localPartInfos objectForKey: [@(remotePartNumber) stringValue]]; + info.crc64 = [tPartInfo[@"crc64"] unsignedLongLongValue]; [uploadedPartInfos addObject:info]; [alreadyUploadIndex addObject:@(remotePartNumber)]; diff --git a/AliyunOSSSDK/OSSDefine.h b/AliyunOSSSDK/OSSDefine.h index dbe8f8a3..324c3a42 100644 --- a/AliyunOSSSDK/OSSDefine.h +++ b/AliyunOSSSDK/OSSDefine.h @@ -54,7 +54,6 @@ #define OSSMaxPartsXMLTOKEN @"MaxParts" #define OSSPartXMLTOKEN @"Part" #define OSSPartNumberXMLTOKEN @"PartNumber" -#define OSSPartHashCodeXMLTOKEN @"HashCrc64ecma" #define OSSClientErrorDomain @"com.aliyun.oss.clientError" #define OSSServerErrorDomain @"com.aliyun.oss.serverError" From a59c9b087ed59f53a67ea0a66ea6746ea205d74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Tue, 11 Sep 2018 18:38:07 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E8=B0=83=E6=95=B4buildCanonicalURL?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C=E5=92=8C=E5=AE=89=E5=8D=93?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E9=80=BB=E8=BE=91=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSNetworkingRequestDelegate.m | 49 ++++++++++----------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/AliyunOSSSDK/OSSNetworkingRequestDelegate.m b/AliyunOSSSDK/OSSNetworkingRequestDelegate.m index e80293ff..afe64f43 100644 --- a/AliyunOSSSDK/OSSNetworkingRequestDelegate.m +++ b/AliyunOSSSDK/OSSNetworkingRequestDelegate.m @@ -72,31 +72,29 @@ - (OSSTask *)buildInternalHttpRequest { } #define URLENCODE(a) [OSSUtil encodeURL:(a)] - OSSLogDebug(@"start to build request"); + OSSLogDebug(@"start to build request") // build base url string - NSString * urlString = self.allNeededMessage.endpoint; - + NSString *urlString = self.allNeededMessage.endpoint; NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:urlString]; + NSString *headerHost = urlComponents.host; - if (self.allNeededMessage.bucketName) { - OSSIPv6Adapter *ipv6Adapter = [OSSIPv6Adapter getInstance]; + if ([self.allNeededMessage.bucketName oss_isNotEmpty]) { if ([OSSUtil isOssOriginBucketHost:urlComponents.host]) { // eg. insert bucket to the begining of host. urlComponents.host = [NSString stringWithFormat:@"%@.%@", self.allNeededMessage.bucketName, urlComponents.host]; - urlString = urlComponents.URL.absoluteString; - } else if ([ipv6Adapter isIPv4Address: urlComponents.host] || [ipv6Adapter isIPv6Address: urlComponents.host]) { - urlString = [urlString stringByAppendingFormat:@"/%@/", self.allNeededMessage.bucketName]; + headerHost = urlComponents.host; + + if (self.isHttpdnsEnable) { + NSString *dnsResult = [OSSUtil getIpByHost: urlComponents.host]; + urlComponents.host = dnsResult; + } } } - urlComponents = [[NSURLComponents alloc] initWithString:urlString]; - NSString * urlHost = urlComponents.host; - if (!self.isAccessViaProxy && [OSSUtil isOssOriginBucketHost:urlHost] && self.isHttpdnsEnable) { - NSString * httpdnsResolvedResult = [OSSUtil getIpByHost:urlHost]; - urlString = [NSString stringWithFormat:@"%@://%@", urlComponents.scheme, httpdnsResolvedResult]; - } + urlString = urlComponents.string; - if (self.allNeededMessage.objectKey) { + // join object name + if ([self.allNeededMessage.objectKey oss_isNotEmpty]) { urlString = [urlString oss_stringByAppendingPathComponentForURL:URLENCODE(self.allNeededMessage.objectKey)]; } @@ -118,22 +116,21 @@ - (OSSTask *)buildInternalHttpRequest { urlString = [NSString stringWithFormat:@"%@?%@", urlString, queryString]; } } - OSSLogDebug(@"built full url: %@", urlString); - - NSString * headerHost = urlHost; - if (![OSSUtil isOssOriginBucketHost:urlHost] && self.allNeededMessage.isHostInCnameExcludeList && self.allNeededMessage.bucketName) { - headerHost = [NSString stringWithFormat:@"%@.%@", self.allNeededMessage.bucketName, urlHost]; - } + OSSLogDebug(@"built full url: %@", urlString) - // set header fields + // generate internal request For NSURLSession self.internalRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]]; - // override default host - [self.internalRequest setValue:headerHost forHTTPHeaderField:@"Host"]; - + // set http method of request if (self.allNeededMessage.httpMethod) { [self.internalRequest setHTTPMethod:self.allNeededMessage.httpMethod]; } + + // set host of header fields + if ([headerHost oss_isNotEmpty]) { + [self.internalRequest setValue:headerHost forHTTPHeaderField:@"Host"]; + } + if (self.allNeededMessage.contentType) { [self.internalRequest setValue:self.allNeededMessage.contentType forHTTPHeaderField:@"Content-Type"]; } @@ -157,7 +154,7 @@ - (OSSTask *)buildInternalHttpRequest { OSSLogVerbose(@"buidlInternalHttpRequest -\nmethod: %@\nurl: %@\nheader: %@", self.internalRequest.HTTPMethod, - self.internalRequest.URL, self.internalRequest.allHTTPHeaderFields); + self.internalRequest.URL, self.internalRequest.allHTTPHeaderFields) #undef URLENCODE//(a) return [OSSTask taskWithResult:nil]; From aaca7d3adcf399fe70295420436fbec02525b282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Wed, 12 Sep 2018 10:41:09 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E5=8F=AA=E6=9C=89=E5=9C=A8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=AE=98=E6=96=B9endpoint=E5=88=9D=E5=A7=8B=E5=8C=96O?= =?UTF-8?q?SSClient=E4=B8=8B=EF=BC=8C=E5=8F=91=E5=87=BA=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=97=B6=E5=9C=A8=E8=AF=B7=E6=B1=82=E5=A4=B4=E4=B8=AD=E6=90=BA?= =?UTF-8?q?=E5=B8=A6Host=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSNetworking.m | 5 +---- AliyunOSSSDK/OSSNetworkingRequestDelegate.m | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/AliyunOSSSDK/OSSNetworking.m b/AliyunOSSSDK/OSSNetworking.m index f74b03bb..b6532633 100644 --- a/AliyunOSSSDK/OSSNetworking.m +++ b/AliyunOSSSDK/OSSNetworking.m @@ -410,9 +410,6 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didRece */ NSString * host = [[task.currentRequest allHTTPHeaderFields] objectForKey:@"Host"]; - if (!host) { - host = task.currentRequest.URL.host; - } if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { if ([self evaluateServerTrust:challenge.protectionSpace.serverTrust forDomain:host]) { @@ -423,7 +420,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didRece disposition = NSURLSessionAuthChallengePerformDefaultHandling; } // Uses the default evaluation for other challenges. - completionHandler(disposition,credential); + completionHandler(disposition, credential); } - (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session diff --git a/AliyunOSSSDK/OSSNetworkingRequestDelegate.m b/AliyunOSSSDK/OSSNetworkingRequestDelegate.m index afe64f43..564be5e0 100644 --- a/AliyunOSSSDK/OSSNetworkingRequestDelegate.m +++ b/AliyunOSSSDK/OSSNetworkingRequestDelegate.m @@ -76,7 +76,7 @@ - (OSSTask *)buildInternalHttpRequest { // build base url string NSString *urlString = self.allNeededMessage.endpoint; NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:urlString]; - NSString *headerHost = urlComponents.host; + NSString *headerHost = nil; if ([self.allNeededMessage.bucketName oss_isNotEmpty]) { if ([OSSUtil isOssOriginBucketHost:urlComponents.host]) { From 1e86567ea8e5846641c8a319495eab58d933014d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Wed, 12 Sep 2018 16:54:09 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSNetworking.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AliyunOSSSDK/OSSNetworking.m b/AliyunOSSSDK/OSSNetworking.m index b6532633..f74b03bb 100644 --- a/AliyunOSSSDK/OSSNetworking.m +++ b/AliyunOSSSDK/OSSNetworking.m @@ -410,6 +410,9 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didRece */ NSString * host = [[task.currentRequest allHTTPHeaderFields] objectForKey:@"Host"]; + if (!host) { + host = task.currentRequest.URL.host; + } if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { if ([self evaluateServerTrust:challenge.protectionSpace.serverTrust forDomain:host]) { @@ -420,7 +423,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didRece disposition = NSURLSessionAuthChallengePerformDefaultHandling; } // Uses the default evaluation for other challenges. - completionHandler(disposition, credential); + completionHandler(disposition,credential); } - (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session From f1de62986c76ca345a200d14c929464e5fee275a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Wed, 12 Sep 2018 17:28:57 +0800 Subject: [PATCH 13/14] release 2.10.7 info --- AliyunOSSSDK/OSSDefine.h | 2 +- AliyunOSSiOS.podspec | 2 +- CHANGLOG.txt | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AliyunOSSSDK/OSSDefine.h b/AliyunOSSSDK/OSSDefine.h index 324c3a42..0dce7c9f 100644 --- a/AliyunOSSSDK/OSSDefine.h +++ b/AliyunOSSSDK/OSSDefine.h @@ -16,7 +16,7 @@ #elif TARGET_OS_OSX #define OSSUAPrefix @"aliyun-sdk-mac" #endif -#define OSSSDKVersion @"2.10.6" +#define OSSSDKVersion @"2.10.7" #define OSSListBucketResultXMLTOKEN @"ListBucketResult" #define OSSNameXMLTOKEN @"Name" diff --git a/AliyunOSSiOS.podspec b/AliyunOSSiOS.podspec index ae10ef50..b0701aea 100644 --- a/AliyunOSSiOS.podspec +++ b/AliyunOSSiOS.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = "AliyunOSSiOS" - s.version = "2.10.6" + s.version = "2.10.7" s.summary = "An iOS SDK for Aliyun Object Storage Service" diff --git a/CHANGLOG.txt b/CHANGLOG.txt index 4dd9d89c..743dac2e 100755 --- a/CHANGLOG.txt +++ b/CHANGLOG.txt @@ -15,6 +15,13 @@ pod dependency: pod 'AliyunOSSiOS' Update Logs: +2018/09/13 +- release 2.10.7 +1.refactor code of building canonical url for request,Keep its logic consistent with android sdk. +2.fix bug about 409 error when using sequentialUpload api. +3.optimize synchronization of time. +4. + 2018/08/30 - release 2.10.6 1.Add sample about resume download object task from oss server; From a94b2d0b3210eecbd340deb931d07424c1d728a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Thu, 13 Sep 2018 12:08:08 +0800 Subject: [PATCH 14/14] =?UTF-8?q?ip=E8=AF=B7=E6=B1=82=E6=97=B6=E5=B0=86buc?= =?UTF-8?q?ket=E6=8B=BC=E5=88=B0=E5=90=8E=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AliyunOSSSDK/OSSNetworkingRequestDelegate.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AliyunOSSSDK/OSSNetworkingRequestDelegate.m b/AliyunOSSSDK/OSSNetworkingRequestDelegate.m index 564be5e0..ec980aef 100644 --- a/AliyunOSSSDK/OSSNetworkingRequestDelegate.m +++ b/AliyunOSSSDK/OSSNetworkingRequestDelegate.m @@ -79,6 +79,7 @@ - (OSSTask *)buildInternalHttpRequest { NSString *headerHost = nil; if ([self.allNeededMessage.bucketName oss_isNotEmpty]) { + OSSIPv6Adapter *ipAdapter = [OSSIPv6Adapter getInstance]; if ([OSSUtil isOssOriginBucketHost:urlComponents.host]) { // eg. insert bucket to the begining of host. urlComponents.host = [NSString stringWithFormat:@"%@.%@", self.allNeededMessage.bucketName, urlComponents.host]; @@ -88,6 +89,8 @@ - (OSSTask *)buildInternalHttpRequest { NSString *dnsResult = [OSSUtil getIpByHost: urlComponents.host]; urlComponents.host = dnsResult; } + } else if ([ipAdapter isIPv4Address:urlComponents.host] || [ipAdapter isIPv6Address:urlComponents.host]) { + urlComponents.path = [NSString stringWithFormat:@"/%@%@",self.allNeededMessage.bucketName, urlComponents.path]; } }