Skip to content

Commit b93265f

Browse files
committed
update QueryZone for configurable uc
1 parent 350526b commit b93265f

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/Qiniu/Storage/Config.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public string RsHost(string ak, string bucket)
8080
Zone z = this.Zone;
8181
if (z == null)
8282
{
83-
z = ZoneHelper.QueryZone(ak, bucket, scheme);
83+
z = ZoneHelper.QueryZone(ak, bucket, UcHost());
8484
}
8585
return string.Format("{0}{1}", scheme, z.RsHost);
8686
}
@@ -97,7 +97,7 @@ public string RsfHost(string ak, string bucket)
9797
Zone z = this.Zone;
9898
if (z == null)
9999
{
100-
z = ZoneHelper.QueryZone(ak, bucket, scheme);
100+
z = ZoneHelper.QueryZone(ak, bucket, UcHost());
101101
}
102102
return string.Format("{0}{1}", scheme, z.RsfHost);
103103
}
@@ -114,7 +114,7 @@ public string ApiHost(string ak, string bucket)
114114
Zone z = this.Zone;
115115
if (z == null)
116116
{
117-
z = ZoneHelper.QueryZone(ak, bucket, scheme);
117+
z = ZoneHelper.QueryZone(ak, bucket, UcHost());
118118
}
119119
return string.Format("{0}{1}", scheme, z.ApiHost);
120120
}
@@ -131,7 +131,7 @@ public string IovipHost(string ak, string bucket)
131131
Zone z = this.Zone;
132132
if (z == null)
133133
{
134-
z = ZoneHelper.QueryZone(ak, bucket, scheme);
134+
z = ZoneHelper.QueryZone(ak, bucket, UcHost());
135135
}
136136
return string.Format("{0}{1}", scheme, z.IovipHost);
137137
}
@@ -148,7 +148,7 @@ public string UpHost(string ak, string bucket)
148148
Zone z = this.Zone;
149149
if (z == null)
150150
{
151-
z = ZoneHelper.QueryZone(ak, bucket, scheme);
151+
z = ZoneHelper.QueryZone(ak, bucket, UcHost());
152152
}
153153
string upHost = z.SrcUpHosts[0];
154154
if (this.UseCdnDomains)

src/Qiniu/Storage/ZoneHelper.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ public class ZoneHelper
2121
private static object rwLock = new object();
2222

2323
/// <summary>
24-
/// 从uc.qbox.me查询得到回复后,解析出upHost,然后根据upHost确定Zone
24+
/// 从 UC 服务查询得到各个服务域名,生成 Zone 对象并返回
2525
/// </summary>
26-
/// <param name="accessKey">AccessKek</param>
26+
/// <param name="accessKey">AccessKey</param>
2727
/// <param name="bucket">空间名称</param>
28-
public static Zone QueryZone(string accessKey, string bucket, string scheme = "https://")
28+
/// <param name="ucHost">UC 域名</param>
29+
public static Zone QueryZone(string accessKey, string bucket, string ucHost = null)
2930
{
3031
ZoneCacheValue zoneCacheValue = null;
3132
string cacheKey = string.Format("{0}:{1}", accessKey, bucket);
@@ -51,11 +52,14 @@ public static Zone QueryZone(string accessKey, string bucket, string scheme = "h
5152
//query from uc api
5253
Zone zone;
5354
HttpResult hr = null;
55+
if (String.IsNullOrEmpty(ucHost))
56+
{
57+
ucHost = "https://" + Config.DefaultUcHost;
58+
}
5459
try
5560
{
56-
string queryUrl = string.Format("{0}{1}/v4/query?ak={2}&bucket={3}",
57-
scheme,
58-
Config.DefaultUcHost,
61+
string queryUrl = string.Format("{0}/v4/query?ak={1}&bucket={2}",
62+
ucHost,
5963
accessKey,
6064
bucket
6165
);

src/QiniuTests/Storage/ConfigTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ public void UcHostTest()
1111
{
1212
Config config = new Config();
1313
string ucHost = config.UcHost();
14-
Assert.AreEqual("http://" + Config.DefaultUcHost, ucHost);
14+
Assert.AreEqual("http://uc.qbox.me", ucHost);
1515
config.SetUcHost("uc.example.com");
1616
ucHost = config.UcHost();
1717
Assert.AreEqual("http://uc.example.com", ucHost);
1818

1919
config = new Config();
2020
config.UseHttps = true;
2121
ucHost = config.UcHost();
22-
Assert.AreEqual("https://" + Config.DefaultUcHost, ucHost);
22+
Assert.AreEqual("https://uc.qbox.me", ucHost);
2323
config.SetUcHost("uc.example.com");
2424
ucHost = config.UcHost();
2525
Assert.AreEqual("https://uc.example.com", ucHost);

0 commit comments

Comments
 (0)