Skip to content

Conversation

@rich7420
Copy link
Contributor

What changes were proposed in this pull request?

In this PR, HEAD Object now handles Range requests just like GET Object does. When you send a Range header, it returns 206 Partial Content with the Content-Range header instead of always returning the full file size.

What is the link to the Apache JIRA

HDDS-14224

How was this patch tested?

https://github.com/rich7420/ozone/actions/runs/20406661096

@rich7420 rich7420 changed the title Support Range header in HeadObject HDDS-14224. Support Range header in HeadObject Dec 21, 2025
@ivandika3 ivandika3 added the s3 S3 Gateway label Dec 21, 2025
Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rich7420 for the patch. Mostly LGTM, few minor code improvements suggested.

Comment on lines +200 to +205
OzoneOutputStream out = bucket.createKey("key1",
value.getBytes(UTF_8).length,
ReplicationConfig.fromTypeAndFactor(ReplicationType.RATIS,
ReplicationFactor.ONE), new HashMap<>());
out.write(value.getBytes(UTF_8));
out.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move key creation to setup() to avoid duplication. While at that, please change to:

try (OutputStream out = ...) {
  out.write(...)
}

S3GAction s3GAction = S3GAction.HEAD_KEY;

OzoneKey key;
RangeHeader rangeHeader = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move to the code block where header is parsed.

Comment on lines +219 to +222
assertEquals("1", response.getHeaderString("Content-Length"));
assertEquals(String.format("bytes 0-0/%d", value.length()),
response.getHeaderString("Content-Range"));
assertEquals("bytes", response.getHeaderString("Accept-Ranges"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use constants from HttpHeaders for "Content-Length", etc..

Comment on lines +209 to +212
keyEndpoint = EndpointBuilder.newObjectEndpointBuilder()
.setClient(client)
.setHeaders(headers)
.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create and set headers on keyEndpoint in setup() and do not create new endpoint in test cases. This also makes it unnecessary to create field for OzoneClient.

assertEquals(String.format("bytes 0-%d/%d", value.length() - 1, value.length()),
response.getHeaderString("Content-Range"));

bucket.deleteKey("key1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move to @AfterEach method to ensure cleanup even in case of test failure.

.build();

//WHEN
Response response = keyEndpoint.head(bucketName, "key1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define constant for "key1" and reuse in creation, lookup and cleanup.

Comment on lines +257 to +260
OS3Exception ex = assertThrows(OS3Exception.class,
() -> keyEndpoint.head(bucketName, "key1"));
assertEquals("InvalidRange", ex.getCode());
assertEquals(416, ex.getHttpCode());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify using EndpointTestUtils:

assertErrorResponse(S3ErrorTable.INVALID_RANGE, () -> keyEndpoint.head(bucketName, "key1"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s3 S3 Gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants