Skip to content

Commit 39670bb

Browse files
authored
uc query add host: uc.qiniuapi.com (#440)
1 parent 32f8709 commit 39670bb

File tree

12 files changed

+85
-23
lines changed

12 files changed

+85
-23
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: setup-cocoapods
2828
uses: maxim-lobanov/setup-cocoapods@v1
2929
with:
30-
version: 1.12.1
30+
version: 1.14.2
3131
- name: Run Cases
3232
env:
3333
QINIU_TEST_ENV: travis

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#Changelog
2+
## 8.7.1(2023-11-23)
3+
- 查询区域的主备域名增加 uc.qiniuapi.com
4+
25
## 8.7.0(2023-10-23)
36
- iOS 最低版本调整至 iOS9
47
- QNFixedZone 新增通过 RegionID 构造实例的方法

Qiniu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Qiniu'
3-
s.version = '8.7.0'
3+
s.version = '8.7.1'
44
s.summary = 'Qiniu Resource Storage SDK for iOS and Mac'
55
s.homepage = 'https://github.com/qiniu/objc-sdk'
66
s.social_media_url = 'http://weibo.com/qiniutek'

QiniuSDK.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@
344344
31FD09252487506300217848 /* QNRetryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31FD09232487506300217848 /* QNRetryTest.m */; };
345345
31FE6A0B25A8320200C02B27 /* QNConnectChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 31FE6A0925A8320200C02B27 /* QNConnectChecker.h */; };
346346
31FE6A0C25A8320200C02B27 /* QNConnectChecker.m in Sources */ = {isa = PBXBuildFile; fileRef = 31FE6A0A25A8320200C02B27 /* QNConnectChecker.m */; };
347+
4511641A2B05C86900F2D9FC /* QNUrlUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 451164182B05C86900F2D9FC /* QNUrlUtils.h */; };
348+
4511641B2B05C86900F2D9FC /* QNUrlUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 451164182B05C86900F2D9FC /* QNUrlUtils.h */; };
349+
4511641C2B05C86900F2D9FC /* QNUrlUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 451164192B05C86900F2D9FC /* QNUrlUtils.m */; };
350+
4511641D2B05C86900F2D9FC /* QNUrlUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 451164192B05C86900F2D9FC /* QNUrlUtils.m */; };
347351
451A36B624BD893D00754A15 /* QNReportConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 451A36B424BD893D00754A15 /* QNReportConfig.h */; settings = {ATTRIBUTES = (Public, ); }; };
348352
451A36B724BD893D00754A15 /* QNReportConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 451A36B524BD893D00754A15 /* QNReportConfig.m */; };
349353
451A36B824BD893D00754A15 /* QNReportConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 451A36B524BD893D00754A15 /* QNReportConfig.m */; };
@@ -591,6 +595,8 @@
591595
31FE6A0925A8320200C02B27 /* QNConnectChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNConnectChecker.h; sourceTree = "<group>"; };
592596
31FE6A0A25A8320200C02B27 /* QNConnectChecker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNConnectChecker.m; sourceTree = "<group>"; };
593597
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 = "<group>"; };
598+
451164182B05C86900F2D9FC /* QNUrlUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUrlUtils.h; sourceTree = "<group>"; };
599+
451164192B05C86900F2D9FC /* QNUrlUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUrlUtils.m; sourceTree = "<group>"; };
594600
451A36B424BD893D00754A15 /* QNReportConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNReportConfig.h; sourceTree = "<group>"; };
595601
451A36B524BD893D00754A15 /* QNReportConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNReportConfig.m; sourceTree = "<group>"; };
596602
4543D6FE24D29B21006E28B1 /* QNDnsPrefetch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNDnsPrefetch.h; sourceTree = "<group>"; };
@@ -765,6 +771,8 @@
765771
3177B70325A30C4500C56293 /* QNSingleFlight.m */,
766772
31E8EA1A2692AC1500BD6DBE /* QNMutableArray.h */,
767773
31E8EA1B2692AC1500BD6DBE /* QNMutableArray.m */,
774+
451164182B05C86900F2D9FC /* QNUrlUtils.h */,
775+
451164192B05C86900F2D9FC /* QNUrlUtils.m */,
768776
);
769777
path = Utils;
770778
sourceTree = "<group>";
@@ -1174,6 +1182,7 @@
11741182
318E2F022552AE05004EDE8C /* QNPHAssetResource.h in Headers */,
11751183
318E2F172552AE2B004EDE8C /* QNRequestTransaction.h in Headers */,
11761184
318E2F312552AE39004EDE8C /* QNConfiguration.h in Headers */,
1185+
4511641B2B05C86900F2D9FC /* QNUrlUtils.h in Headers */,
11771186
318E2F132552AE2B004EDE8C /* QNUploadRegionInfo.h in Headers */,
11781187
318E2F192552AE2B004EDE8C /* QNHttpSingleRequest.h in Headers */,
11791188
318E2F352552AE39004EDE8C /* QNUploadManager.h in Headers */,
@@ -1228,6 +1237,7 @@
12281237
31259E3424E3D02C00CF7531 /* NSData+QNGZip.h in Headers */,
12291238
31A6985526DCDB3F00D84ABC /* QNServerConfigCache.h in Headers */,
12301239
3188D4FD264913B800183CAE /* QNUploadSourceStream.h in Headers */,
1240+
4511641A2B05C86900F2D9FC /* QNUrlUtils.h in Headers */,
12311241
31304CB92563DA03001034D2 /* QNUploadRequestState.h in Headers */,
12321242
3177B70425A30C4500C56293 /* QNSingleFlight.h in Headers */,
12331243
31C2EEE3242DE86300713A33 /* QNUtils.h in Headers */,
@@ -1585,6 +1595,7 @@
15851595
31E8EA1E2692AC1500BD6DBE /* QNMutableArray.m in Sources */,
15861596
31C2EED5242CC52600713A33 /* QNDnsCacheFile.m in Sources */,
15871597
3149A1E02462A57400A2A15B /* QNUploadServer.m in Sources */,
1598+
4511641C2B05C86900F2D9FC /* QNUrlUtils.m in Sources */,
15881599
31F553C12457FFB0000B66AD /* QNPipeline.m in Sources */,
15891600
4551E56024CE81DA00447285 /* QNInetAddress.m in Sources */,
15901601
CC25135D244C7EB3003F4C65 /* QNBaseUpload.m in Sources */,
@@ -1713,6 +1724,7 @@
17131724
31E8EA1F2692AC1500BD6DBE /* QNMutableArray.m in Sources */,
17141725
31F553C22457FFB0000B66AD /* QNPipeline.m in Sources */,
17151726
3149A1E12462A57400A2A15B /* QNUploadServer.m in Sources */,
1727+
4511641D2B05C86900F2D9FC /* QNUrlUtils.m in Sources */,
17161728
4551E56124CE81DA00447285 /* QNInetAddress.m in Sources */,
17171729
31F553AF2457D2E5000B66AD /* QNALAssetFile.m in Sources */,
17181730
313B380F2575E49400FBB57B /* QNPartsUploadPerformer.m in Sources */,

QiniuSDK/Common/QNAutoZone.m

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ + (QNCache *)zoneShareCache {
6464
static dispatch_once_t onceToken;
6565
dispatch_once(&onceToken, ^{
6666
QNCacheOption *option = [[QNCacheOption alloc] init];
67-
option.version = @"v1.0.0";
67+
option.version = @"v2";
6868
queryCache = [QNCache cache:[QNZonesInfo class] option:option];
6969
});
7070
return queryCache;
@@ -130,7 +130,6 @@ - (void)preQuery:(QNUpToken *)token on:(QNPrequeryReturn)ret {
130130
return;
131131
}
132132

133-
__block int32_t saveTime = 0;
134133
kQNWeakSelf;
135134
QNSingleFlight *singleFlight = [QNAutoZone UCQuerySingleFlight];
136135
[singleFlight perform:token.index action:^(QNSingleFlightComplete _Nonnull complete) {
@@ -162,13 +161,8 @@ - (void)preQuery:(QNUpToken *)token on:(QNPrequeryReturn)ret {
162161
if (responseInfo && responseInfo.isOK) {
163162
QNZonesInfo *zonesInfo = [QNZonesInfo infoWithDictionary:response];
164163
if ([zonesInfo isValid]) {
165-
@synchronized (cacheKey) {
166-
if (saveTime == 0) {
167-
saveTime++;
168-
[self setZonesInfo:zonesInfo forKey:cacheKey];
169-
[[QNAutoZone zoneShareCache] cache:zonesInfo forKey:cacheKey atomically:false];
170-
}
171-
}
164+
[self setZonesInfo:zonesInfo forKey:cacheKey];
165+
[[QNAutoZone zoneShareCache] cache:zonesInfo forKey:cacheKey atomically:false];
172166
ret(0, responseInfo, metrics);
173167
} else {
174168
ret(NSURLErrorCannotDecodeRawData, responseInfo, metrics);

QiniuSDK/Common/QNConfig.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#import <Foundation/Foundation.h>
1010

1111
//MARK: -- 内部布置 尽量不要修改
12-
#define kQNPreQueryHost00 @"kodo-config.qiniuapi.com"
13-
#define kQNPreQueryHost01 @"uc.qbox.me"
14-
#define kQNPreQueryHost02 @"api.qiniu.com"
15-
#define kQNPreQueryHosts @[kQNPreQueryHost00, kQNPreQueryHost01, kQNPreQueryHost02]
12+
#define kQNPreQueryHost00 @"uc.qiniuapi.com"
13+
#define kQNPreQueryHost01 @"kodo-config.qiniuapi.com"
14+
#define kQNPreQueryHost02 @"uc.qbox.me"
15+
#define kQNPreQueryHost03 @"api.qiniu.com"
16+
#define kQNPreQueryHosts @[kQNPreQueryHost00, kQNPreQueryHost01, kQNPreQueryHost02, kQNPreQueryHost03]
1617

1718
#define kQNUpLogHost @"uplog.qbox.me"

QiniuSDK/Common/QNZoneInfo.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "QNZoneInfo.h"
10+
#import "QNUtils.h"
1011

1112
NSString * const QNZoneInfoSDKDefaultIOHost = @"default_io_host";
1213
NSString * const QNZoneInfoEmptyRegionId = @"none";
@@ -52,11 +53,17 @@ + (QNZoneInfo *)zoneInfoWithMainHosts:(NSArray <NSString *> *)mainHosts
5253
return zoneInfo;
5354
}
5455

55-
+ (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detailInfo {
56-
if (![detailInfo isKindOfClass:[NSDictionary class]]) {
56+
+ (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detail {
57+
if (![detail isKindOfClass:[NSDictionary class]]) {
5758
return nil;
5859
}
5960

61+
NSMutableDictionary *detailInfo = [detail mutableCopy];
62+
if (detailInfo[@"timestamp"] == nil) {
63+
detailInfo[@"timestamp"] = @([QNUtils currentTimestamp]/1000);
64+
}
65+
long timestamp = [detailInfo[@"timestamp"] longValue];
66+
6067
NSString *regionId = [detailInfo objectForKey:@"region"];
6168
if (regionId == nil) {
6269
regionId = QNZoneInfoEmptyRegionId;
@@ -73,6 +80,7 @@ + (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detailInfo {
7380

7481
NSMutableArray *allHosts = [NSMutableArray array];
7582
QNZoneInfo *zoneInfo = [[QNZoneInfo alloc] init:ttl regionId:regionId];
83+
zoneInfo.buildDate = [NSDate dateWithTimeIntervalSince1970:timestamp];
7684
zoneInfo.http3Enabled = http3Enabled;
7785
if ([domains isKindOfClass:[NSArray class]]) {
7886
zoneInfo.domains = domains;
@@ -84,7 +92,7 @@ + (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detailInfo {
8492
}
8593
zoneInfo.allHosts = [allHosts copy];
8694

87-
zoneInfo.detailInfo = detailInfo;
95+
zoneInfo.detailInfo = [detailInfo copy];
8896

8997
return zoneInfo;
9098
}

QiniuSDK/Http/Request/QNHttpRegionRequest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import "QNHttpRegionRequest.h"
1515
#import "QNConfiguration.h"
1616
#import "QNUploadOption.h"
17+
#import "QNUrlUtils.h"
1718
#import "NSURLRequest+QNRequest.h"
1819

1920
#import "QNUploadRequestMetrics.h"
@@ -138,9 +139,8 @@ - (void)performRequest:(id <QNUploadServer>)server
138139

139140
self.currentServer = server;
140141

141-
NSString *scheme = self.config.useHttps ? @"https://" : @"http://";
142142
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
143-
NSString *urlString = [NSString stringWithFormat:@"%@%@%@", scheme, serverHost, action ?: @""];
143+
NSString *urlString = [NSString stringWithFormat:@"%@%@", [QNUrlUtils setHostScheme:serverHost useHttps:self.config.useHttps], action ?: @""];
144144
request.URL = [NSURL URLWithString:urlString];
145145
request.HTTPMethod = method;
146146
[request setAllHTTPHeaderFields:headers];

QiniuSDK/Utils/QNUrlUtils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// QNUrlUtils.h
3+
// QiniuSDK
4+
//
5+
// Created by yangsen on 2023/11/16.
6+
// Copyright © 2023 Qiniu. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface QNUrlUtils : NSObject
14+
15+
+ (NSString *)setHostScheme:(NSString *)host useHttps:(BOOL)useHttps;
16+
17+
@end
18+
19+
NS_ASSUME_NONNULL_END

QiniuSDK/Utils/QNUrlUtils.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// QNUrlUtils.m
3+
// QiniuSDK
4+
//
5+
// Created by yangsen on 2023/11/16.
6+
// Copyright © 2023 Qiniu. All rights reserved.
7+
//
8+
9+
#import "QNUrlUtils.h"
10+
11+
@implementation QNUrlUtils
12+
13+
+ (NSString *)setHostScheme:(NSString *)host useHttps:(BOOL)useHttps {
14+
if (host == nil || host.length == 0) {
15+
return nil;
16+
}
17+
18+
if ([host hasPrefix:@"http://"] || [host hasPrefix:@"https://"]) {
19+
return host;
20+
}
21+
22+
return [NSString stringWithFormat:@"%@%@", (useHttps ? @"https://" : @"http://"), host];
23+
}
24+
25+
@end

0 commit comments

Comments
 (0)