Skip to content

Commit b3d3461

Browse files
committed
Refacotry BucketInfo.CreateByRegion()
1 parent 2692567 commit b3d3461

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Entites/BucketInfo.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,27 @@ public static BucketInfo CreateByCname(Uri uri, string bucket)
6969
/// <returns></returns>
7070
public static BucketInfo CreateByRegion(string region, string bucketName, bool useHttps = false, bool useInternal = false)
7171
{
72-
var baseDomain = useInternal? "-internal.aliyuncs.com" : ".aliyuncs.com";
73-
var method = useHttps ? "https://" : "http://";
72+
var uriBuilder = new UriBuilder();
73+
uriBuilder.Scheme = useHttps ? "https" : "http";
74+
uriBuilder.Host = region + (useInternal ? "-internal.aliyuncs.com" : ".aliyuncs.com");
7475

7576
var bucket = new BucketInfo()
7677
{
7778
IsCname = false,
7879
BucketName = bucketName,
79-
IsHttps = useHttps
80+
IsHttps = useHttps,
81+
EndpointUri = uriBuilder.Uri
8082
};
8183

82-
bucket.EndpointUri = new Uri(method + region + baseDomain);
83-
84-
// bucket名称为空的情况,直接访问oss
85-
bucket.BucketUri = String.IsNullOrEmpty(bucketName)? bucket.EndpointUri : new Uri(method + bucketName + "." + region + baseDomain);
84+
if(string.IsNullOrEmpty(bucketName))
85+
{
86+
bucket.BucketUri = bucket.EndpointUri;
87+
}
88+
else
89+
{
90+
uriBuilder.Host = bucketName + "." + uriBuilder.Host;
91+
bucket.BucketUri = uriBuilder.Uri;
92+
}
8693

8794
return bucket;
8895
}

0 commit comments

Comments
 (0)