Skip to content

Commit

Permalink
支持设置长短连接,预签名URL使用临时密钥时生成问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnnqin committed Feb 25, 2022
1 parent 766efc4 commit d598ee1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion QCloudCSharpSDK/COSXML/COSXML-Netcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Deterministic>true</Deterministic>

<PackageId>Tencent.QCloud.Cos.Sdk</PackageId>
<Version>5.4.27.0</Version>
<Version>5.4.28.0</Version>
<Authors>Tencent</Authors>
<Company>Tencent</Company>
<description>Tencent Cloud COS(Cloud Object Service) .Net SDK</description>
Expand Down
2 changes: 1 addition & 1 deletion QCloudCSharpSDK/COSXML/Common/CosVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace COSXML.Common
{
public sealed class CosVersion
{
private static string SDKVersion = "5.4.27.0";
private static string SDKVersion = "5.4.28.0";

public static string GetUserAgent()
{
Expand Down
12 changes: 12 additions & 0 deletions QCloudCSharpSDK/COSXML/CosXmlConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ public Builder SetReadWriteTimeoutMs(int readWriteTimeoutMs)
return this;
}

/// <summary>
/// 设置是否使用 Keep-Alive 长连接
/// </summary>
/// <param name="keepAlive"></param>
/// <returns></returns>
public Builder SetHttpKeepAlive(bool keepAlive)
{
this.httpClientConfigBuilder.SetHttpKeepAlive(keepAlive);

return this;
}

/// <summary>
/// 设置 HTTP 代理主机
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions QCloudCSharpSDK/COSXML/CosXmlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -886,11 +886,11 @@ public string GenerateSignURL(PreSignatureStruct preSignatureStruct)
}

// 针对需要二次 Encode 的 request Param 特殊处理
Regex rgx = new Regex("q-url-param-list=.*&");
string paramlist = rgx.Match(sign).ToString().Split('=')[1].ToString();
Regex rgx = new Regex("q-url-param-list=.*&q-signature");
string paramlist = rgx.Match(sign).ToString().Split('=')[1].ToString().Split('&')[0].ToString();
paramlist = paramlist.Trim('&');
paramlist = URLEncodeUtils.Encode(paramlist).ToLower();
string encodedStr = "q-url-param-list=" + paramlist + "&";
string encodedStr = "q-url-param-list=" + paramlist + "&q-signature";
sign = rgx.Replace(sign, encodedStr);

queryBuilder.Append(sign);
Expand Down
3 changes: 3 additions & 0 deletions QCloudCSharpSDK/COSXML/Network/CommandTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ private static void HandleHttpWebRequestHeaders(Request request, HttpWebRequest
// set allow auto redirect
httpWebRequest.AllowAutoRedirect = config.AllowAutoRedirect;

// set connection
httpWebRequest.KeepAlive = config.KeepAlive;

// notice: it is not allowed to set common headers with the WebHeaderCollection.Accept
// such as: Connection,Content-Length,Content-Type,Date,Expect. Host,If-Modified-Since,Range, Referer,Transfer-Encoding,User-Agent,Proxy-Connection
//step2: set header and connection properity by request.heders
Expand Down
21 changes: 21 additions & 0 deletions QCloudCSharpSDK/COSXML/Network/HttpClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class HttpClientConfig

private string proxyDomain;

private bool keepAlive;

private HttpClientConfig(Builder builder)
{
this.userAgent = builder.userAgent;
Expand All @@ -43,6 +45,7 @@ private HttpClientConfig(Builder builder)
this.proxyUserName = builder.proxyUserName;
this.proxyUserPassword = builder.proxyUserPassword;
this.proxyDomain = builder.proxyDomain;
this.keepAlive = builder.keepAlive;
}

public string UserAgnet
Expand Down Expand Up @@ -147,6 +150,15 @@ public string ProxyDomain

}

public bool KeepAlive
{
get
{

return keepAlive;
}
}

public class Builder
{
internal string userAgent = CosVersion.GetUserAgent();
Expand All @@ -171,6 +183,8 @@ public class Builder

internal string proxyDomain;

internal bool keepAlive = true;

public Builder()
{

Expand Down Expand Up @@ -251,6 +265,13 @@ public Builder SetProxyDomain(string domain)
return this;
}

public Builder SetHttpKeepAlive(bool keepAlive)
{
this.keepAlive = keepAlive;

return this;
}

public HttpClientConfig Build()
{

Expand Down

0 comments on commit d598ee1

Please sign in to comment.