Skip to content

Commit

Permalink
uc query add host: uc.qiniuapi.com (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn authored Nov 23, 2023
1 parent 32f8709 commit 39670bb
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#Changelog
## 8.7.1(2023-11-23)
- 查询区域的主备域名增加 uc.qiniuapi.com

## 8.7.0(2023-10-23)
- iOS 最低版本调整至 iOS9
- QNFixedZone 新增通过 RegionID 构造实例的方法
Expand Down
2 changes: 1 addition & 1 deletion Qiniu.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
12 changes: 12 additions & 0 deletions QiniuSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -591,6 +595,8 @@
31FE6A0925A8320200C02B27 /* QNConnectChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNConnectChecker.h; sourceTree = "<group>"; };
31FE6A0A25A8320200C02B27 /* QNConnectChecker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNConnectChecker.m; sourceTree = "<group>"; };
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>"; };
451164182B05C86900F2D9FC /* QNUrlUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUrlUtils.h; sourceTree = "<group>"; };
451164192B05C86900F2D9FC /* QNUrlUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUrlUtils.m; sourceTree = "<group>"; };
451A36B424BD893D00754A15 /* QNReportConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNReportConfig.h; sourceTree = "<group>"; };
451A36B524BD893D00754A15 /* QNReportConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNReportConfig.m; sourceTree = "<group>"; };
4543D6FE24D29B21006E28B1 /* QNDnsPrefetch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNDnsPrefetch.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -765,6 +771,8 @@
3177B70325A30C4500C56293 /* QNSingleFlight.m */,
31E8EA1A2692AC1500BD6DBE /* QNMutableArray.h */,
31E8EA1B2692AC1500BD6DBE /* QNMutableArray.m */,
451164182B05C86900F2D9FC /* QNUrlUtils.h */,
451164192B05C86900F2D9FC /* QNUrlUtils.m */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
12 changes: 3 additions & 9 deletions QiniuSDK/Common/QNAutoZone.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions QiniuSDK/Common/QNConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#import <Foundation/Foundation.h>

//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"
14 changes: 11 additions & 3 deletions QiniuSDK/Common/QNZoneInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "QNZoneInfo.h"
#import "QNUtils.h"

NSString * const QNZoneInfoSDKDefaultIOHost = @"default_io_host";
NSString * const QNZoneInfoEmptyRegionId = @"none";
Expand Down Expand Up @@ -52,11 +53,17 @@ + (QNZoneInfo *)zoneInfoWithMainHosts:(NSArray <NSString *> *)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;
Expand All @@ -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;
Expand All @@ -84,7 +92,7 @@ + (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detailInfo {
}
zoneInfo.allHosts = [allHosts copy];

zoneInfo.detailInfo = detailInfo;
zoneInfo.detailInfo = [detailInfo copy];

return zoneInfo;
}
Expand Down
4 changes: 2 additions & 2 deletions QiniuSDK/Http/Request/QNHttpRegionRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "QNHttpRegionRequest.h"
#import "QNConfiguration.h"
#import "QNUploadOption.h"
#import "QNUrlUtils.h"
#import "NSURLRequest+QNRequest.h"

#import "QNUploadRequestMetrics.h"
Expand Down Expand Up @@ -138,9 +139,8 @@ - (void)performRequest:(id <QNUploadServer>)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];
Expand Down
19 changes: 19 additions & 0 deletions QiniuSDK/Utils/QNUrlUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// QNUrlUtils.h
// QiniuSDK
//
// Created by yangsen on 2023/11/16.
// Copyright © 2023 Qiniu. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface QNUrlUtils : NSObject

+ (NSString *)setHostScheme:(NSString *)host useHttps:(BOOL)useHttps;

@end

NS_ASSUME_NONNULL_END
25 changes: 25 additions & 0 deletions QiniuSDK/Utils/QNUrlUtils.m
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion QiniuSDK/Utils/QNVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
/**
* sdk 版本
*/
static NSString *const kQiniuVersion = @"8.7.0";
static NSString *const kQiniuVersion = @"8.7.1";
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
通过 CocoaPods

```ruby
pod "Qiniu", "~> 8.7.0"
pod "Qiniu", "~> 8.7.1"
```

通过 Swift Package Manager (Xcode 11+)
Expand All @@ -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")
],
// ...
)
Expand Down

0 comments on commit 39670bb

Please sign in to comment.