Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复host处理,兼容IP访问 #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion QCloudCSharpSDK/COSXML/Auth/IQCloudSigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ public string Source(Request request)
lowerKeySourceHeaders.Add(pair.Key.ToLower(), pair.Value);
}

lowerKeySourceHeaders.Add("host", request.Host);
// 可能通过Request设置Host参数,供内网IP访问
if (!lowerKeySourceHeaders.ContainsKey("host"))
lowerKeySourceHeaders.Add("host", request.Host);

if (headerKeysToSign.Contains("content-length"))
{
Expand Down
25 changes: 25 additions & 0 deletions QCloudCSharpSDK/COSXML/COSXML-Netcore.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COSXML-Netcore", "COSXML-Netcore.csproj", "{FC694C68-F0E3-411F-8E6C-2E9F94826016}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FC694C68-F0E3-411F-8E6C-2E9F94826016}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC694C68-F0E3-411F-8E6C-2E9F94826016}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC694C68-F0E3-411F-8E6C-2E9F94826016}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC694C68-F0E3-411F-8E6C-2E9F94826016}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BDF01472-9935-4900-B0CA-6802E01BF1AB}
EndGlobalSection
EndGlobal
32 changes: 32 additions & 0 deletions QCloudCSharpSDK/COSXML/Transfer/COSXMLCopyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ internal void Copy()

headObjectRequest = new HeadObjectRequest(copySource.bucket, copySource.key);
headObjectRequest.Region = copySource.region;
if (customHeaders != null)
{
headObjectRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.HeadObject(headObjectRequest, delegate (CosResult cosResult)
{
lock (syncExit)
Expand Down Expand Up @@ -156,6 +160,10 @@ private void SimpleCopy()
copyObjectRequest = new CopyObjectRequest(bucket, key);
copyObjectRequest.SetCopyMetaDataDirective(Common.CosMetaDataDirective.Copy);
copyObjectRequest.SetCopySource(copySource);
if (customHeaders != null)
{
copyObjectRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.CopyObject(copyObjectRequest,
delegate (CosResult cosResult)
{
Expand Down Expand Up @@ -231,6 +239,10 @@ private void MultiPartCopy()
private void InitMultiUploadPart()
{
initMultiUploadRequest = new InitMultipartUploadRequest(bucket, key);
if (customHeaders != null)
{
initMultiUploadRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.InitMultipartUpload(initMultiUploadRequest, delegate (CosResult cosResult)
{
lock (syncExit)
Expand Down Expand Up @@ -274,6 +286,10 @@ private void InitMultiUploadPart()
private void ListParts()
{
listPartsRequest = new ListPartsRequest(bucket, key, uploadId);
if (customHeaders != null)
{
listPartsRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.ListParts(listPartsRequest, delegate (CosResult cosResult)
{
lock (syncExit)
Expand Down Expand Up @@ -338,6 +354,10 @@ private void PartCopy()

uploadPartCopyRequest.SetCopySource(copySource);
uploadPartCopyRequest.SetCopyRange(sliceStruct.sliceStart, sliceStruct.sliceEnd);
if (customHeaders != null)
{
uploadPartCopyRequest.SetRequestHeaders(customHeaders);
}
uploadCopyCopyRequestList.Add(uploadPartCopyRequest);
cosXmlServer.PartCopy(uploadPartCopyRequest, delegate (CosResult result)
{
Expand Down Expand Up @@ -490,6 +510,10 @@ private void UpdateSliceNums(ListPartsResult listPartsResult)
private void CompleteMultipartUpload()
{
completeMultiUploadRequest = new CompleteMultipartUploadRequest(bucket, key, uploadId);
if (customHeaders != null)
{
completeMultiUploadRequest.SetRequestHeaders(customHeaders);
}

foreach (SliceStruct sliceStruct in sliceList)
{
Expand Down Expand Up @@ -588,6 +612,10 @@ public void OnFailed(CosClientException clientEx, CosServerException serverEx)
private void Abort()
{
abortMultiUploadRequest = new AbortMultipartUploadRequest(bucket, key, uploadId);
if (customHeaders != null)
{
abortMultiUploadRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.AbortMultiUpload(abortMultiUploadRequest,
delegate (CosResult cosResult)
{
Expand All @@ -604,6 +632,10 @@ private void Abort()
private void DeleteObject()
{
deleteObjectRequest = new DeleteObjectRequest(bucket, key);
if (customHeaders != null)
{
deleteObjectRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.DeleteObject(deleteObjectRequest,
delegate (CosResult cosResult)
{
Expand Down
10 changes: 9 additions & 1 deletion QCloudCSharpSDK/COSXML/Transfer/COSXMLDownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public COSXMLDownloadTask(GetObjectRequest request)
this.localDir = request.localDir + System.IO.Path.DirectorySeparatorChar;
}
this.localFileName = request.localFileName;
SetHeaders(request.GetRequestHeaders());
}

public void SetRange(long rangeStart, long rangeEnd)
Expand Down Expand Up @@ -197,7 +198,10 @@ internal void Download()
UpdateTaskState(TaskState.Waiting);
//对象是否存在
headObjectRequest = new HeadObjectRequest(bucket, key);

if (customHeaders != null)
{
headObjectRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.HeadObject(headObjectRequest, delegate (CosResult cosResult)
{
lock (syncExit)
Expand Down Expand Up @@ -402,6 +406,10 @@ private void ConcurrentGetObject(string crc64ecma)
GetObjectRequest subGetObjectRequest = new GetObjectRequest(bucket, key, localDir, tmpFileName);
tmpFilePaths.Add(localDir + tmpFileName);
subGetObjectRequest.SetRange(slice.sliceStart, slice.sliceEnd);
if (customHeaders != null)
{
subGetObjectRequest.SetRequestHeaders(customHeaders);
}
getObjectRequestsList.Add(subGetObjectRequest);
// 计算出来只有一个分块, 而且不是Resume或重试剩的一个, 即不走并发下载, 用GetObject的进度回调给客户端
if (progressCallback != null && this.sliceList.Count == 1 && sliceToRemove.Count == 0)
Expand Down
30 changes: 30 additions & 0 deletions QCloudCSharpSDK/COSXML/Transfer/COSXMLUploadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ private void CheckResumeblaUpload()
{
listMultiUploadsRequest = new ListMultiUploadsRequest(bucket);
listMultiUploadsRequest.SetPrefix(key);
if (customHeaders != null)
{
listMultiUploadsRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.ListMultiUploads(listMultiUploadsRequest, delegate (CosResult cosResult)
{
// 取最新符合条件的uploadId
Expand Down Expand Up @@ -362,6 +366,10 @@ private void CheckAllUploadParts(string uploadId)
{
bool checkSucc = true;
listPartsRequest = new ListPartsRequest(bucket, key, uploadId);
if (customHeaders != null)
{
listPartsRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.ListParts(listPartsRequest, delegate (CosResult cosResult)
{
lock (syncExit)
Expand Down Expand Up @@ -433,6 +441,10 @@ private void CheckAllUploadParts(string uploadId)
private void ListMultiParts()
{
listPartsRequest = new ListPartsRequest(bucket, key, uploadId);
if (customHeaders != null)
{
listPartsRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.ListParts(listPartsRequest, delegate (CosResult cosResult)
{
lock (syncExit)
Expand Down Expand Up @@ -509,6 +521,11 @@ private void UploadPart()
UploadPartRequest uploadPartRequest = new UploadPartRequest(bucket, key, sliceStruct.partNumber, uploadId, srcPath,
sliceStruct.sliceStart, sliceStruct.sliceLength);

if (customHeaders != null)
{
uploadPartRequest.SetRequestHeaders(customHeaders);
}

if (customHeaders != null && customHeaders.ContainsKey(CosRequestHeaderKey.X_COS_TRAFFIC_LIMIT))
{
string trafficLimit = customHeaders[CosRequestHeaderKey.X_COS_TRAFFIC_LIMIT];
Expand Down Expand Up @@ -640,6 +657,11 @@ private void CompleteMultipartUpload()
completeMultiUploadRequest.SetPartNumberAndETag(sliceStruct.partNumber, sliceStruct.eTag);
}

if (customHeaders != null)
{
completeMultiUploadRequest.SetRequestHeaders(customHeaders);
}

cosXmlServer.CompleteMultiUpload(completeMultiUploadRequest, delegate (CosResult result)
{
lock (syncExit)
Expand Down Expand Up @@ -838,6 +860,10 @@ public void OnFailed(CosClientException clientEx, CosServerException serverEx)
private void Abort()
{
abortMultiUploadRequest = new AbortMultipartUploadRequest(bucket, key, uploadId);
if (customHeaders != null)
{
abortMultiUploadRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.AbortMultiUpload(abortMultiUploadRequest,
delegate (CosResult cosResult)
{
Expand All @@ -855,6 +881,10 @@ private void Abort()
private void DeleteObject()
{
deleteObjectRequest = new DeleteObjectRequest(bucket, key);
if (customHeaders != null)
{
deleteObjectRequest.SetRequestHeaders(customHeaders);
}
cosXmlServer.DeleteObject(deleteObjectRequest,
delegate (CosResult cosResult)
{
Expand Down