Skip to content

Commit

Permalink
#709 fixing put for object and new bucket request
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony McHugh authored and ebozduman committed Nov 15, 2022
1 parent 52abff5 commit e0d1910
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public async Task MakeBucketAsync(MakeBucketArgs args, CancellationToken cancell
if (args.Location == "us-east-1")
if (Region != string.Empty)
args.Location = Region;
args.IsBucketCreationRequest = true;
var requestMessageBuilder = await CreateRequest(args).ConfigureAwait(false);
using var response = await ExecuteTaskAsync(NoErrorHandlers, requestMessageBuilder, cancellationToken)
.ConfigureAwait(false);
Expand Down
2 changes: 2 additions & 0 deletions Minio/DataModel/BucketArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public BucketArgs()
Headers = new Dictionary<string, string>();
}

public bool IsBucketCreationRequest { get; set; } = false;

internal string BucketName { get; set; }

internal Dictionary<string, string> Headers { get; set; }
Expand Down
10 changes: 7 additions & 3 deletions Minio/MinioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ private void ArgsCheck(Args args)
internal async Task<HttpRequestMessageBuilder> CreateRequest<T>(BucketArgs<T> args) where T : BucketArgs<T>
{
ArgsCheck(args);
var requestMessageBuilder = await CreateRequest(args.RequestMethod, args.BucketName).ConfigureAwait(false);
var requestMessageBuilder =
await CreateRequest(args.RequestMethod, args.BucketName,
isBucketCreationRequest: args.IsBucketCreationRequest).ConfigureAwait(false);
return args.BuildRequest(requestMessageBuilder);
}

Expand Down Expand Up @@ -281,6 +283,7 @@ private void ArgsCheck(Args args)
/// <param name="contentType">Content Type</param>
/// <param name="body">request body</param>
/// <param name="resourcePath">query string</param>
/// <param name="isBucketCreationRequest">boolean to define bucket creation</param>
/// <returns>A HttpRequestMessage builder</returns>
/// <exception cref="BucketNotFoundException">When bucketName is invalid</exception>
internal async Task<HttpRequestMessageBuilder> CreateRequest(
Expand All @@ -290,14 +293,15 @@ private void ArgsCheck(Args args)
Dictionary<string, string> headerMap = null,
string contentType = "application/octet-stream",
byte[] body = null,
string resourcePath = null)
string resourcePath = null,
bool isBucketCreationRequest = false)
{
var region = string.Empty;
if (bucketName != null)
{
utils.ValidateBucketName(bucketName);
// Fetch correct region for bucket if this is not a bucket creation
if (method != HttpMethod.Put)
if (!isBucketCreationRequest)
region = await GetRegion(bucketName).ConfigureAwait(false);
}

Expand Down

0 comments on commit e0d1910

Please sign in to comment.