Skip to content

Commit

Permalink
update 3.20.7
Browse files Browse the repository at this point in the history
  • Loading branch information
goodcode-best committed Jul 30, 2020
1 parent ede6e34 commit 94382ad
Show file tree
Hide file tree
Showing 21 changed files with 427 additions and 239 deletions.
35 changes: 35 additions & 0 deletions Help on License
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
This help guides Huawei engineers to add or modify the license announcement
during the development.

In the case that you add a new file, the text below should be added in the head.
Copyright 2019 Huawei Technologies Co.,Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.


In the case that you modify one existing file, the text below should be added after
the exiting license.
Huawei has modified this source file.

Copyright 2019 Huawei Technologies Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
4 changes: 2 additions & 2 deletions Internal/Auth/AbstractSigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override void _DoAuth(HttpRequest request, HttpContext context, IHeade
request.Headers.Add(Constants.CommonHeaders.Authorization, auth);
}

internal override IDictionary<string,string> GetSignature(HttpRequest request, HttpContext context, IHeaders iheaders)
internal override IDictionary<string, string> GetSignature(HttpRequest request, HttpContext context, IHeaders iheaders)
{
StringBuilder stringToSign = new StringBuilder();

Expand Down Expand Up @@ -175,7 +175,7 @@ internal override IDictionary<string,string> GetSignature(HttpRequest request, H

if (LoggerMgr.IsDebugEnabled)
{
LoggerMgr.Debug("StringToSign:" + stringToSign.ToString());
LoggerMgr.Debug("StringToSign: ******");
}

IDictionary<string, string> ret = new Dictionary<string, string>();
Expand Down
16 changes: 8 additions & 8 deletions Internal/Auth/V4Signer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class V4Signer : Signer
private const string RequestKey = "aws4_request";
internal const string Algorithm = "AWS4-HMAC-SHA256";
internal static readonly string ScopeSuffix = string.Format("/{0}/{1}/{2}", RegionKey, ServiceKey, RequestKey);


private V4Signer()
{
Expand All @@ -52,7 +52,7 @@ protected override void _DoAuth(HttpRequest request, HttpContext context, IHeade
.ToString();
request.Headers.Add(Constants.CommonHeaders.Authorization, auth);
}

internal static string CaculateSignature(string stringToSign, string shortDate, string sk)
{
byte[] key = CommonUtil.HmacSha256("AWS4" + sk, shortDate);
Expand Down Expand Up @@ -169,7 +169,7 @@ internal static string GetTemporarySignature(HttpRequest request, HttpContext co

canonicalRequest.Append("\n");

if(headerDict == null)
if (headerDict == null)
{
// Canonical Headers
headerDict = new Dictionary<string, string>();
Expand All @@ -182,7 +182,7 @@ internal static string GetTemporarySignature(HttpRequest request, HttpContext co
headerDict.Add(entry.Key.Trim().ToLower(), entry.Value);
}
}

foreach (string key in signedHeaderList)
{
canonicalRequest.Append(key).Append(":").Append(headerDict[key]).Append("\n");
Expand All @@ -195,11 +195,11 @@ internal static string GetTemporarySignature(HttpRequest request, HttpContext co
canonicalRequest.Append("\n");

// Hashed Payload
canonicalRequest.Append(string.IsNullOrEmpty(payload)? UnsignedPayload : payload);
canonicalRequest.Append(string.IsNullOrEmpty(payload) ? UnsignedPayload : payload);

if (LoggerMgr.IsDebugEnabled)
{
LoggerMgr.Debug("CanonicalRequest:" + canonicalRequest);
LoggerMgr.Debug("CanonicalRequest: ******");
}

StringBuilder stringToSign = new StringBuilder(Algorithm).Append("\n")
Expand All @@ -209,14 +209,14 @@ internal static string GetTemporarySignature(HttpRequest request, HttpContext co

if (LoggerMgr.IsDebugEnabled)
{
LoggerMgr.Debug("StringToSign:" + stringToSign.ToString());
LoggerMgr.Debug("StringToSign: ******");
}

return CaculateSignature(stringToSign.ToString(), dateDict["ShortDate"], context.SecurityProvider.Sk);
}


internal override IDictionary<string,string> GetSignature(HttpRequest request, HttpContext context, IHeaders iheaders)
internal override IDictionary<string, string> GetSignature(HttpRequest request, HttpContext context, IHeaders iheaders)
{
CommonUtil.AddHeader(request, iheaders.ContentSha256Header(), ContentSha256);
IDictionary<string, string> tempDict = new Dictionary<string, string>();
Expand Down
46 changes: 22 additions & 24 deletions Internal/CommonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,40 @@ public static void ParseObsWebServiceResponse(HttpResponse httpResponse, ObsWebS
else if (key.StartsWith(iheaders.HeaderPrefix()))
{
key = key.Substring(iheaders.HeaderPrefix().Length);
}else if (key.StartsWith(Constants.ObsHeaderMetaPrefix))
}
else if (key.StartsWith(Constants.ObsHeaderMetaPrefix))
{
key = key.Substring(Constants.ObsHeaderMetaPrefix.Length);
}else if (key.StartsWith(Constants.ObsHeaderPrefix))
}
else if (key.StartsWith(Constants.ObsHeaderPrefix))
{
key = key.Substring(Constants.ObsHeaderPrefix.Length);
}
response.Headers.Add(key, header.Value);
}

response.Headers.Add(key, header.Value);
}
}

public static void ParseErrorResponse(Stream stream, ObsException exception)
{
if (stream != null)
using (XmlReader reader = XmlReader.Create(stream))
{
using (XmlReader reader = XmlReader.Create(stream))
while (reader.Read())
{
while (reader.Read())
if ("Code".Equals(reader.Name))
{
exception.ErrorCode = reader.ReadString();
}
else if ("Message".Equals(reader.Name))
{
exception.ErrorMessage = reader.ReadString();
}
else if ("RequestId".Equals(reader.Name))
{
exception.RequestId = reader.ReadString();
}
else if ("HostId".Equals(reader.Name))
{
if ("Code".Equals(reader.Name))
{
exception.ErrorCode = reader.ReadString();
}
else if ("Message".Equals(reader.Name))
{
exception.ErrorMessage = reader.ReadString();
}
else if ("RequestId".Equals(reader.Name))
{
exception.RequestId = reader.ReadString();
}
else if ("HostId".Equals(reader.Name))
{
exception.HostId = reader.ReadString();
}
exception.HostId = reader.ReadString();
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions Internal/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ internal static class CommonHeaders
{
public const string Connection = "Connection";

public const string Authorization = "Authorization";
public const string Range = "Range";

public const string CacheControl = "Cache-Control";
public const string LastModified = "Last-Modified";

public const string ContentDisposition = "Content-Disposition";
public const string Location = "Location";

public const string ContentEncoding = "Content-Encoding";
public const string Expires = "Expires";

public const string ContentLength = "Content-Length";
public const string Date = "Date";

public const string ContentMd5 = "Content-MD5";

public const string Location = "Location";
public const string ContentLength = "Content-Length";

public const string ContentType = "Content-Type";
public const string ContentEncoding = "Content-Encoding";

public const string Date = "Date";
public const string ContentDisposition = "Content-Disposition";

public const string Expires = "Expires";
public const string ContentType = "Content-Type";

public const string ETag = "ETag";

public const string LastModified = "Last-Modified";
public const string CacheControl = "Cache-Control";

public const string Range = "Range";
public const string Authorization = "Authorization";

public const string Host = "Host";

Expand Down Expand Up @@ -133,7 +133,7 @@ internal static class ObsRequestParams

public const string V2HeaderMetaPrefix = "x-amz-meta-";

public const string ObsSdkVersion = "3.19.7.1";
public const string ObsSdkVersion = "3.20.7";

public const string ObsApiHeader = "api";
public const string ObsApiHeaderWithPrefix = ObsHeaderPrefix + ObsApiHeader;
Expand Down Expand Up @@ -177,6 +177,10 @@ internal static class ObsRequestParams

public const string ThreeAz = "3az";

public const string ObsHeadErrorCode = "x-obs-error-code";

public const string ObsHeadErrorMessage = "x-obs-error-message";

public static IList<string> AllowedResponseHttpHeaders
{
get
Expand Down
6 changes: 3 additions & 3 deletions Internal/HttpClient.async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal HttpResponse EndPerformRequest(HttpObsAsyncResult result)
}
throw ParseObsException(response, "Try to redirect, but location is null!", context);
}
else if ((statusCode >= 400 && statusCode < 500 && statusCode != 408) || statusCode == 304)
else if ((statusCode >= 400 && statusCode < 500) || statusCode == 304)
{
ObsException exception = ParseObsException(response, "Request error", context);
if (Constants.RequestTimeout.Equals(exception.ErrorCode))
Expand All @@ -109,7 +109,7 @@ internal HttpResponse EndPerformRequest(HttpObsAsyncResult result)
}
throw exception;
}
else if (statusCode >= 500 || statusCode == 408)
else if (statusCode >= 500)
{
if (ShouldRetry(request, null, result.RetryCount, maxErrorRetry))
{
Expand All @@ -120,7 +120,7 @@ internal HttpResponse EndPerformRequest(HttpObsAsyncResult result)
}
else if (result.RetryCount > maxErrorRetry && LoggerMgr.IsErrorEnabled)
{
LoggerMgr.Error("Encountered too many 5xx or 408 errors");
LoggerMgr.Error("Encountered too many 5xx errors");
}
throw ParseObsException(response, "Request error", context);
}
Expand Down
36 changes: 24 additions & 12 deletions Internal/HttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ namespace OBS.Internal
{
internal partial class HttpClient
{


internal HttpClient(ObsConfig obsConfig)
{
ServicePointManager.DefaultConnectionLimit = obsConfig.ConnectionLimit;
ServicePointManager.MaxServicePointIdleTime = obsConfig.MaxIdleTime;
ServicePointManager.Expect100Continue = false;



if (obsConfig.SecurityProtocolType.HasValue)
{
ServicePointManager.SecurityProtocol = obsConfig.SecurityProtocolType.Value;
Expand All @@ -59,7 +55,6 @@ internal Signer GetSigner(HttpContext context)

internal IHeaders GetIHeaders(HttpContext context)
{

switch (context.ChooseAuthType)
{
case AuthTypeEnum.V2:
Expand All @@ -72,7 +67,6 @@ internal IHeaders GetIHeaders(HttpContext context)

internal HttpResponse DoRequest(HttpRequest httpRequest, HttpContext context)
{

if (!context.SkipAuth)
{
this.GetSigner(context).DoAuth(httpRequest, context, this.GetIHeaders(context));
Expand Down Expand Up @@ -200,7 +194,7 @@ internal HttpResponse PerformRequest(HttpRequest request, HttpContext context, i
}
throw ParseObsException(response, "Try to redirect, but location is null!", context);
}
else if ((statusCode >= 400 && statusCode < 500 && statusCode != 408) || statusCode == 304)
else if ((statusCode >= 400 && statusCode < 500) || statusCode == 304)
{
ObsException exception = ParseObsException(response, "Request error", context);
if (Constants.RequestTimeout.Equals(exception.ErrorCode))
Expand All @@ -221,7 +215,7 @@ internal HttpResponse PerformRequest(HttpRequest request, HttpContext context, i
}
throw exception;
}
else if (statusCode >= 500 || statusCode == 408)
else if (statusCode >= 500)
{
if (ShouldRetry(request, null, retryCount, maxErrorRetry))
{
Expand All @@ -230,7 +224,7 @@ internal HttpResponse PerformRequest(HttpRequest request, HttpContext context, i
}
else if (retryCount > maxErrorRetry && LoggerMgr.IsErrorEnabled)
{
LoggerMgr.Error("Encountered too many 5xx or 408 errors");
LoggerMgr.Error("Encountered too many 5xx errors");
}
throw ParseObsException(response, "Request error", context);
}
Expand Down Expand Up @@ -280,7 +274,7 @@ private void PrepareRetry(HttpRequest request, HttpResponse response, int retryC
if (request.Content != null && (originPos >= 0 && request.Content.CanSeek))
{
request.Content.Seek(originPos, SeekOrigin.Begin);
if(request.Content is TransferStream)
if (request.Content is TransferStream)
{
(request.Content as TransferStream).ResetReadProgress();
}
Expand All @@ -306,18 +300,35 @@ private ObsException ParseObsException(HttpResponse response, string message, Ex
if (response != null)
{
exception.StatusCode = response.StatusCode;
string temp;
try
{
CommonParser.ParseErrorResponse(response.Content, exception);
if (response.Content.Length > 0)
{
CommonParser.ParseErrorResponse(response.Content, exception);
}
else if (response.Headers.ContainsKey(Constants.ObsHeadErrorCode) && response.Headers.ContainsKey(Constants.ObsHeadErrorMessage))
{
response.Headers.TryGetValue(Constants.ObsHeadErrorCode, out temp);
exception.ErrorCode = temp;
response.Headers.TryGetValue(Constants.ObsHeadErrorMessage, out temp);
exception.ErrorMessage = temp;
}
else
{
exception.ErrorCode = response.StatusCode.ToString();
exception.ErrorMessage = response.Failure.Message;
}
}
catch (Exception ee)
{
exception.ErrorMessage = ee.Message;
if (LoggerMgr.IsErrorEnabled)
{
LoggerMgr.Error(ee.Message, ee);
}
}
string temp;

if (response.Headers.TryGetValue(this.GetIHeaders(context).RequestId2Header(), out temp))
{
exception.ObsId2 = temp;
Expand Down Expand Up @@ -461,6 +472,7 @@ private static void AddHeaders(HttpWebRequest webRequest, HttpRequest request,
{
continue;
}

webRequest.Headers.Add(header.Key, header.Value);
}
#else
Expand Down
Loading

0 comments on commit 94382ad

Please sign in to comment.