From 39670bb1a21f0fa2ca796f178fb5eca869b6266d Mon Sep 17 00:00:00 2001 From: yangsen Date: Thu, 23 Nov 2023 15:43:26 +0800 Subject: [PATCH] uc query add host: uc.qiniuapi.com (#440) --- .github/workflows/ci-test.yml | 2 +- CHANGELOG.md | 3 +++ Qiniu.podspec | 2 +- QiniuSDK.xcodeproj/project.pbxproj | 12 ++++++++++ QiniuSDK/Common/QNAutoZone.m | 12 +++------- QiniuSDK/Common/QNConfig.h | 9 ++++---- QiniuSDK/Common/QNZoneInfo.m | 14 +++++++++--- QiniuSDK/Http/Request/QNHttpRegionRequest.m | 4 ++-- QiniuSDK/Utils/QNUrlUtils.h | 19 ++++++++++++++++ QiniuSDK/Utils/QNUrlUtils.m | 25 +++++++++++++++++++++ QiniuSDK/Utils/QNVersion.h | 2 +- README.md | 4 ++-- 12 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 QiniuSDK/Utils/QNUrlUtils.h create mode 100644 QiniuSDK/Utils/QNUrlUtils.m diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index da761df0..404e80a1 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -27,7 +27,7 @@ jobs: - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: - version: 1.12.1 + version: 1.14.2 - name: Run Cases env: QINIU_TEST_ENV: travis diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f4d6f82..6ebf5e50 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ #Changelog +## 8.7.1(2023-11-23) +- 查询区域的主备域名增加 uc.qiniuapi.com + ## 8.7.0(2023-10-23) - iOS 最低版本调整至 iOS9 - QNFixedZone 新增通过 RegionID 构造实例的方法 diff --git a/Qiniu.podspec b/Qiniu.podspec index b49d2a00..ee88e463 100755 --- a/Qiniu.podspec +++ b/Qiniu.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Qiniu' - s.version = '8.7.0' + s.version = '8.7.1' s.summary = 'Qiniu Resource Storage SDK for iOS and Mac' s.homepage = 'https://github.com/qiniu/objc-sdk' s.social_media_url = 'http://weibo.com/qiniutek' diff --git a/QiniuSDK.xcodeproj/project.pbxproj b/QiniuSDK.xcodeproj/project.pbxproj index d02dc126..b4e5b596 100644 --- a/QiniuSDK.xcodeproj/project.pbxproj +++ b/QiniuSDK.xcodeproj/project.pbxproj @@ -344,6 +344,10 @@ 31FD09252487506300217848 /* QNRetryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31FD09232487506300217848 /* QNRetryTest.m */; }; 31FE6A0B25A8320200C02B27 /* QNConnectChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 31FE6A0925A8320200C02B27 /* QNConnectChecker.h */; }; 31FE6A0C25A8320200C02B27 /* QNConnectChecker.m in Sources */ = {isa = PBXBuildFile; fileRef = 31FE6A0A25A8320200C02B27 /* QNConnectChecker.m */; }; + 4511641A2B05C86900F2D9FC /* QNUrlUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 451164182B05C86900F2D9FC /* QNUrlUtils.h */; }; + 4511641B2B05C86900F2D9FC /* QNUrlUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 451164182B05C86900F2D9FC /* QNUrlUtils.h */; }; + 4511641C2B05C86900F2D9FC /* QNUrlUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 451164192B05C86900F2D9FC /* QNUrlUtils.m */; }; + 4511641D2B05C86900F2D9FC /* QNUrlUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 451164192B05C86900F2D9FC /* QNUrlUtils.m */; }; 451A36B624BD893D00754A15 /* QNReportConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 451A36B424BD893D00754A15 /* QNReportConfig.h */; settings = {ATTRIBUTES = (Public, ); }; }; 451A36B724BD893D00754A15 /* QNReportConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 451A36B524BD893D00754A15 /* QNReportConfig.m */; }; 451A36B824BD893D00754A15 /* QNReportConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 451A36B524BD893D00754A15 /* QNReportConfig.m */; }; @@ -591,6 +595,8 @@ 31FE6A0925A8320200C02B27 /* QNConnectChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNConnectChecker.h; sourceTree = ""; }; 31FE6A0A25A8320200C02B27 /* QNConnectChecker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNConnectChecker.m; sourceTree = ""; }; 32036F4A07041AC3410DBF2F /* Pods-QiniuSDK_Mac.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_Mac.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_Mac/Pods-QiniuSDK_Mac.release.xcconfig"; sourceTree = ""; }; + 451164182B05C86900F2D9FC /* QNUrlUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUrlUtils.h; sourceTree = ""; }; + 451164192B05C86900F2D9FC /* QNUrlUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUrlUtils.m; sourceTree = ""; }; 451A36B424BD893D00754A15 /* QNReportConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNReportConfig.h; sourceTree = ""; }; 451A36B524BD893D00754A15 /* QNReportConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNReportConfig.m; sourceTree = ""; }; 4543D6FE24D29B21006E28B1 /* QNDnsPrefetch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNDnsPrefetch.h; sourceTree = ""; }; @@ -765,6 +771,8 @@ 3177B70325A30C4500C56293 /* QNSingleFlight.m */, 31E8EA1A2692AC1500BD6DBE /* QNMutableArray.h */, 31E8EA1B2692AC1500BD6DBE /* QNMutableArray.m */, + 451164182B05C86900F2D9FC /* QNUrlUtils.h */, + 451164192B05C86900F2D9FC /* QNUrlUtils.m */, ); path = Utils; sourceTree = ""; @@ -1174,6 +1182,7 @@ 318E2F022552AE05004EDE8C /* QNPHAssetResource.h in Headers */, 318E2F172552AE2B004EDE8C /* QNRequestTransaction.h in Headers */, 318E2F312552AE39004EDE8C /* QNConfiguration.h in Headers */, + 4511641B2B05C86900F2D9FC /* QNUrlUtils.h in Headers */, 318E2F132552AE2B004EDE8C /* QNUploadRegionInfo.h in Headers */, 318E2F192552AE2B004EDE8C /* QNHttpSingleRequest.h in Headers */, 318E2F352552AE39004EDE8C /* QNUploadManager.h in Headers */, @@ -1228,6 +1237,7 @@ 31259E3424E3D02C00CF7531 /* NSData+QNGZip.h in Headers */, 31A6985526DCDB3F00D84ABC /* QNServerConfigCache.h in Headers */, 3188D4FD264913B800183CAE /* QNUploadSourceStream.h in Headers */, + 4511641A2B05C86900F2D9FC /* QNUrlUtils.h in Headers */, 31304CB92563DA03001034D2 /* QNUploadRequestState.h in Headers */, 3177B70425A30C4500C56293 /* QNSingleFlight.h in Headers */, 31C2EEE3242DE86300713A33 /* QNUtils.h in Headers */, @@ -1585,6 +1595,7 @@ 31E8EA1E2692AC1500BD6DBE /* QNMutableArray.m in Sources */, 31C2EED5242CC52600713A33 /* QNDnsCacheFile.m in Sources */, 3149A1E02462A57400A2A15B /* QNUploadServer.m in Sources */, + 4511641C2B05C86900F2D9FC /* QNUrlUtils.m in Sources */, 31F553C12457FFB0000B66AD /* QNPipeline.m in Sources */, 4551E56024CE81DA00447285 /* QNInetAddress.m in Sources */, CC25135D244C7EB3003F4C65 /* QNBaseUpload.m in Sources */, @@ -1713,6 +1724,7 @@ 31E8EA1F2692AC1500BD6DBE /* QNMutableArray.m in Sources */, 31F553C22457FFB0000B66AD /* QNPipeline.m in Sources */, 3149A1E12462A57400A2A15B /* QNUploadServer.m in Sources */, + 4511641D2B05C86900F2D9FC /* QNUrlUtils.m in Sources */, 4551E56124CE81DA00447285 /* QNInetAddress.m in Sources */, 31F553AF2457D2E5000B66AD /* QNALAssetFile.m in Sources */, 313B380F2575E49400FBB57B /* QNPartsUploadPerformer.m in Sources */, diff --git a/QiniuSDK/Common/QNAutoZone.m b/QiniuSDK/Common/QNAutoZone.m index 4023512f..d59fad10 100644 --- a/QiniuSDK/Common/QNAutoZone.m +++ b/QiniuSDK/Common/QNAutoZone.m @@ -64,7 +64,7 @@ + (QNCache *)zoneShareCache { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ QNCacheOption *option = [[QNCacheOption alloc] init]; - option.version = @"v1.0.0"; + option.version = @"v2"; queryCache = [QNCache cache:[QNZonesInfo class] option:option]; }); return queryCache; @@ -130,7 +130,6 @@ - (void)preQuery:(QNUpToken *)token on:(QNPrequeryReturn)ret { return; } - __block int32_t saveTime = 0; kQNWeakSelf; QNSingleFlight *singleFlight = [QNAutoZone UCQuerySingleFlight]; [singleFlight perform:token.index action:^(QNSingleFlightComplete _Nonnull complete) { @@ -162,13 +161,8 @@ - (void)preQuery:(QNUpToken *)token on:(QNPrequeryReturn)ret { if (responseInfo && responseInfo.isOK) { QNZonesInfo *zonesInfo = [QNZonesInfo infoWithDictionary:response]; if ([zonesInfo isValid]) { - @synchronized (cacheKey) { - if (saveTime == 0) { - saveTime++; - [self setZonesInfo:zonesInfo forKey:cacheKey]; - [[QNAutoZone zoneShareCache] cache:zonesInfo forKey:cacheKey atomically:false]; - } - } + [self setZonesInfo:zonesInfo forKey:cacheKey]; + [[QNAutoZone zoneShareCache] cache:zonesInfo forKey:cacheKey atomically:false]; ret(0, responseInfo, metrics); } else { ret(NSURLErrorCannotDecodeRawData, responseInfo, metrics); diff --git a/QiniuSDK/Common/QNConfig.h b/QiniuSDK/Common/QNConfig.h index bc90a9f2..b39401bf 100644 --- a/QiniuSDK/Common/QNConfig.h +++ b/QiniuSDK/Common/QNConfig.h @@ -9,9 +9,10 @@ #import //MARK: -- 内部布置 尽量不要修改 -#define kQNPreQueryHost00 @"kodo-config.qiniuapi.com" -#define kQNPreQueryHost01 @"uc.qbox.me" -#define kQNPreQueryHost02 @"api.qiniu.com" -#define kQNPreQueryHosts @[kQNPreQueryHost00, kQNPreQueryHost01, kQNPreQueryHost02] +#define kQNPreQueryHost00 @"uc.qiniuapi.com" +#define kQNPreQueryHost01 @"kodo-config.qiniuapi.com" +#define kQNPreQueryHost02 @"uc.qbox.me" +#define kQNPreQueryHost03 @"api.qiniu.com" +#define kQNPreQueryHosts @[kQNPreQueryHost00, kQNPreQueryHost01, kQNPreQueryHost02, kQNPreQueryHost03] #define kQNUpLogHost @"uplog.qbox.me" diff --git a/QiniuSDK/Common/QNZoneInfo.m b/QiniuSDK/Common/QNZoneInfo.m index b3f117ff..305a2968 100644 --- a/QiniuSDK/Common/QNZoneInfo.m +++ b/QiniuSDK/Common/QNZoneInfo.m @@ -7,6 +7,7 @@ // #import "QNZoneInfo.h" +#import "QNUtils.h" NSString * const QNZoneInfoSDKDefaultIOHost = @"default_io_host"; NSString * const QNZoneInfoEmptyRegionId = @"none"; @@ -52,11 +53,17 @@ + (QNZoneInfo *)zoneInfoWithMainHosts:(NSArray *)mainHosts return zoneInfo; } -+ (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detailInfo { - if (![detailInfo isKindOfClass:[NSDictionary class]]) { ++ (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detail { + if (![detail isKindOfClass:[NSDictionary class]]) { return nil; } + NSMutableDictionary *detailInfo = [detail mutableCopy]; + if (detailInfo[@"timestamp"] == nil) { + detailInfo[@"timestamp"] = @([QNUtils currentTimestamp]/1000); + } + long timestamp = [detailInfo[@"timestamp"] longValue]; + NSString *regionId = [detailInfo objectForKey:@"region"]; if (regionId == nil) { regionId = QNZoneInfoEmptyRegionId; @@ -73,6 +80,7 @@ + (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detailInfo { NSMutableArray *allHosts = [NSMutableArray array]; QNZoneInfo *zoneInfo = [[QNZoneInfo alloc] init:ttl regionId:regionId]; + zoneInfo.buildDate = [NSDate dateWithTimeIntervalSince1970:timestamp]; zoneInfo.http3Enabled = http3Enabled; if ([domains isKindOfClass:[NSArray class]]) { zoneInfo.domains = domains; @@ -84,7 +92,7 @@ + (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detailInfo { } zoneInfo.allHosts = [allHosts copy]; - zoneInfo.detailInfo = detailInfo; + zoneInfo.detailInfo = [detailInfo copy]; return zoneInfo; } diff --git a/QiniuSDK/Http/Request/QNHttpRegionRequest.m b/QiniuSDK/Http/Request/QNHttpRegionRequest.m index 26131811..fee44fb9 100644 --- a/QiniuSDK/Http/Request/QNHttpRegionRequest.m +++ b/QiniuSDK/Http/Request/QNHttpRegionRequest.m @@ -14,6 +14,7 @@ #import "QNHttpRegionRequest.h" #import "QNConfiguration.h" #import "QNUploadOption.h" +#import "QNUrlUtils.h" #import "NSURLRequest+QNRequest.h" #import "QNUploadRequestMetrics.h" @@ -138,9 +139,8 @@ - (void)performRequest:(id )server self.currentServer = server; - NSString *scheme = self.config.useHttps ? @"https://" : @"http://"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; - NSString *urlString = [NSString stringWithFormat:@"%@%@%@", scheme, serverHost, action ?: @""]; + NSString *urlString = [NSString stringWithFormat:@"%@%@", [QNUrlUtils setHostScheme:serverHost useHttps:self.config.useHttps], action ?: @""]; request.URL = [NSURL URLWithString:urlString]; request.HTTPMethod = method; [request setAllHTTPHeaderFields:headers]; diff --git a/QiniuSDK/Utils/QNUrlUtils.h b/QiniuSDK/Utils/QNUrlUtils.h new file mode 100644 index 00000000..af6090c2 --- /dev/null +++ b/QiniuSDK/Utils/QNUrlUtils.h @@ -0,0 +1,19 @@ +// +// QNUrlUtils.h +// QiniuSDK +// +// Created by yangsen on 2023/11/16. +// Copyright © 2023 Qiniu. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface QNUrlUtils : NSObject + ++ (NSString *)setHostScheme:(NSString *)host useHttps:(BOOL)useHttps; + +@end + +NS_ASSUME_NONNULL_END diff --git a/QiniuSDK/Utils/QNUrlUtils.m b/QiniuSDK/Utils/QNUrlUtils.m new file mode 100644 index 00000000..ed3ff46d --- /dev/null +++ b/QiniuSDK/Utils/QNUrlUtils.m @@ -0,0 +1,25 @@ +// +// QNUrlUtils.m +// QiniuSDK +// +// Created by yangsen on 2023/11/16. +// Copyright © 2023 Qiniu. All rights reserved. +// + +#import "QNUrlUtils.h" + +@implementation QNUrlUtils + ++ (NSString *)setHostScheme:(NSString *)host useHttps:(BOOL)useHttps { + if (host == nil || host.length == 0) { + return nil; + } + + if ([host hasPrefix:@"http://"] || [host hasPrefix:@"https://"]) { + return host; + } + + return [NSString stringWithFormat:@"%@%@", (useHttps ? @"https://" : @"http://"), host]; +} + +@end diff --git a/QiniuSDK/Utils/QNVersion.h b/QiniuSDK/Utils/QNVersion.h index 45350979..56d5be71 100755 --- a/QiniuSDK/Utils/QNVersion.h +++ b/QiniuSDK/Utils/QNVersion.h @@ -11,4 +11,4 @@ /** * sdk 版本 */ -static NSString *const kQiniuVersion = @"8.7.0"; +static NSString *const kQiniuVersion = @"8.7.1"; diff --git a/README.md b/README.md index 11837321..c0f223ba 100755 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 通过 CocoaPods ```ruby -pod "Qiniu", "~> 8.7.0" +pod "Qiniu", "~> 8.7.1" ``` 通过 Swift Package Manager (Xcode 11+) @@ -26,7 +26,7 @@ File -> Swift Packages -> Add Package Dependency,输入库链接,选择相 库对接: let package = Package( dependencies: [ - .package(url: "https://github.com/qiniu/objc-sdk", from: "8.7.0") + .package(url: "https://github.com/qiniu/objc-sdk", from: "8.7.1") ], // ... )