@@ -16,6 +16,7 @@ - (instancetype) init
1616 if (!self) {
1717 return self;
1818 }
19+ _isPrefixURL = YES ;
1920 _serviceName = @" myqcloud.com" ;
2021 return self;
2122}
@@ -53,33 +54,59 @@ -(NSURL *)serverURLWithBucket:(NSString *)bucket appID:(NSString *)appID regionN
5354 return nil ;
5455 }
5556
56- NSString * formattedBucketName = [self formattedBucket: bucket withAPPID: appID];
57+ NSString * formattedBucketName = [self formattedBucket: bucket withAPPID: appID]; ;
5758 NSString *regionNametmp = nil ;
5859 if (regionName) {
5960 regionNametmp = regionName;
6061 }else {
6162 regionNametmp = self.regionName ;
6263 }
63- NSURL * serverURL = [NSURL URLWithString: [NSString stringWithFormat: @" %@ ://%@ -%@ .cos.%@ .%@ " ,scheme,formattedBucketName,appID,regionNametmp,self .serviceName]];
64+ NSString *tmpBucket = formattedBucketName;
65+ if (appID) {
66+ tmpBucket = [NSString stringWithFormat: @" %@ -%@ " ,formattedBucketName,appID];
67+ }
68+ NSURL *serverURL;
69+
70+ if (_isPrefixURL) {
71+ if (regionNametmp) {
72+ serverURL = [NSURL URLWithString: [NSString stringWithFormat: @" %@ ://%@ .cos.%@ .%@ " ,scheme,tmpBucket,regionNametmp,self .serviceName]];
73+ }else {
74+ serverURL = [NSURL URLWithString: [NSString stringWithFormat: @" %@ ://%@ .cos.%@ " ,scheme,tmpBucket,self .serviceName]];
75+ }
76+ }else {
77+ if (regionNametmp) {
78+ serverURL = [NSURL URLWithString: [NSString stringWithFormat: @" %@ ://cos.%@ .%@ /%@ " ,scheme,regionNametmp,self .serviceName,tmpBucket]];
79+ }else {
80+ serverURL = [NSURL URLWithString: [NSString stringWithFormat: @" %@ ://cos.%@ /%@ " ,scheme,self .serviceName,tmpBucket]];
81+ }
82+ }
83+
6484 return serverURL;
6585}
66-
86+ -(void )setIsPrefixURL : (BOOL )isPrefixURL {
87+ _isPrefixURL = isPrefixURL;
88+ }
6789- (void )setRegionName : (QCloudRegion)regionName {
6890 // Region 仅允许由 a-z, A-Z, 0-9, 英文句号. 和 - 构成。
69- NSParameterAssert (regionName);
70- static NSString *regularExpression = @" [a-zA-Z0-9.-]*" ;
71- BOOL isLegal = [regionName matchesRegularExpression: regularExpression];
72- NSAssert (isLegal, @" Region name contains illegal character! It can only contains a-z, A-Z, 0-9, '.' and '-' " );
73- if (!isLegal) {
74- QCloudLogDebug (@" Region %@ contains illeagal character, setter returns immediately" , regionName);
75- return ;
91+ if ([self .serviceName isEqualToString: @" myqcloud.com" ]) {
92+ NSParameterAssert (regionName);
93+ static NSString *regularExpression = @" [a-zA-Z0-9.-]*" ;
94+ BOOL isLegal = [regionName matchesRegularExpression: regularExpression];
95+ NSAssert (isLegal, @" Region name contains illegal character! It can only contains a-z, A-Z, 0-9, '.' and '-' " );
96+ if (!isLegal) {
97+ QCloudLogDebug (@" Region %@ contains illeagal character, setter returns immediately" , regionName);
98+ return ;
99+ }
76100 }
101+
102+
77103 _regionName = regionName;
78104}
79105- (id )copyWithZone : (NSZone *)zone {
80106 QCloudCOSXMLEndPoint* endpoint = [super copyWithZone: nil ];
81107 endpoint.regionName = self.regionName ;
82108 endpoint.serviceName = self.serviceName ;
109+ endpoint.isPrefixURL = self.isPrefixURL ;
83110 return endpoint;
84111}
85112@end
0 commit comments