Skip to content

Commit

Permalink
The PR resolves an issue reported under #132.
Browse files Browse the repository at this point in the history
Use existing query parameter string from blobstore response and then append digest.  Test updated to ensure existing query parameters are maintained

Signed-off-by: Daniel Robinson <[email protected]>
  • Loading branch information
daniel-pebble committed Aug 9, 2024
1 parent 20cfbce commit b7d567f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/OrasProject.Oras/Registry/Remote/BlobStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public async Task PushAsync(Descriptor expected, Stream content, CancellationTok
// add digest key to query string with expected digest value
var req = new HttpRequestMessage(HttpMethod.Put, new UriBuilder(url)
{
Query = $"digest={HttpUtility.UrlEncode(expected.Digest)}"
Query = $"{url.Query}&digest={HttpUtility.UrlEncode(expected.Digest)}"
}.Uri);
req.Content = new StreamContent(content);
req.Content.Headers.ContentLength = expected.Size;
Expand Down
8 changes: 7 additions & 1 deletion tests/OrasProject.Oras.Tests/Remote/RepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,19 +1082,25 @@ public async Task BlobStore_PushAsync()
};
var gotBlob = new byte[blob.Length];
var uuid = Guid.NewGuid().ToString();
var existingQueryParameter = "existingParam=value";

var func = (HttpRequestMessage req, CancellationToken cancellationToken) =>
{
var res = new HttpResponseMessage();
res.RequestMessage = req;
if (req.Method == HttpMethod.Post && req.RequestUri?.AbsolutePath == $"/v2/test/blobs/uploads/")
{
res.StatusCode = HttpStatusCode.Accepted;
res.Headers.Add("Location", "/v2/test/blobs/uploads/" + uuid);
res.Headers.Add("Location", $"/v2/test/blobs/uploads/{uuid}?{existingQueryParameter}");
return res;
}

if (req.Method == HttpMethod.Put && req.RequestUri?.AbsolutePath == "/v2/test/blobs/uploads/" + uuid)
{
// Assert that the existing query parameter is present
var queryParameters = HttpUtility.ParseQueryString(req.RequestUri.Query);
Assert.Equal("value", queryParameters["existingParam"]);

if (req.Headers.TryGetValues("Content-Type", out var contentType) &&
contentType.FirstOrDefault() != "application/octet-stream")
{
Expand Down

0 comments on commit b7d567f

Please sign in to comment.