Merge pull request #6257 from Jefemy/develop

Change url prefix addition in S3 uploader
This commit is contained in:
Jaex 2022-05-15 03:40:09 +03:00 committed by GitHub
commit 1a23637e5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -421,6 +421,11 @@ public static bool HasPrefix(string url)
return URLPrefixes.Any(x => url.StartsWith(x, StringComparison.InvariantCultureIgnoreCase));
}
public static string GetPrefix(string url)
{
return URLPrefixes.Find(x => url.StartsWith(x, StringComparison.InvariantCultureIgnoreCase));
}
public static string FixPrefix(string url, string prefix = "http://")
{
if (!string.IsNullOrEmpty(url) && !HasPrefix(url))

View file

@ -125,6 +125,7 @@ public override UploadResult Upload(Stream stream, string fileName)
isPathStyleRequest = true;
}
string scheme = URLHelpers.GetPrefix(Settings.Endpoint);
string endpoint = URLHelpers.RemovePrefixes(Settings.Endpoint);
string host = isPathStyleRequest ? endpoint : $"{Settings.Bucket}.{endpoint}";
string algorithm = "AWS4-HMAC-SHA256";
@ -205,8 +206,8 @@ public override UploadResult Upload(Stream stream, string fileName)
headers.Remove("Host");
headers.Remove("Content-Type");
string url = URLHelpers.CombineURL(host, canonicalURI);
url = URLHelpers.ForcePrefix(url, "https://");
string url = URLHelpers.CombineURL(scheme + host, canonicalURI);
url = URLHelpers.FixPrefix(url, "https://");
SendRequest(HttpMethod.PUT, url, stream, contentType, null, headers);