fix(cloudfront): serve viewer Range GETs (#5377)

A distribution ignored a viewer's Range header: an S3 origin answered
every GET with the whole object and 200, while advertising
Accept-Ranges: bytes, and a custom origin behind a cache or origin
request policy never saw the header, so seeking in a video or resuming
a download read the object from the start.

An S3 origin now serves the one byte range asked for as 206 with its
Content-Range, read from the snapshot GetObject serves, and answers 416
when the range starts past the end of the object. Any other Range gets
the whole object, as CloudFront answers a Range it does not accept and
as S3 does not serve several ranges in one request. A custom origin gets
the viewer's Range and If-Range on every GET or HEAD with a Range
whatever the forwarding settings, as CloudFront forwards a range GET to
the origin and a HEAD can then report the range's length, and its answer
is passed on. A custom error page is served whole.

A Range now applies only while the If-Range sent with it, if any, still
describes the object: a strong ETag equal to the object's, or an
HTTP-date equal to its Last-Modified, matched exactly as RFC 9110
section 13.1.5 requires. Otherwise the whole object is served. This
holds for GetObject, HeadObject and the S3 origin. A presigned URL that
signs Range must also sign an If-Range the request carries, as the S3
User Guide requires.

HeadObject honors Range as the API Reference describes: a satisfiable
range sets Content-Length to the length of the range, leaving out the
whole-object checksum as a ranged GetObject does, and one past the end
answers 416, while a Range that is not one valid range is ignored, as
before. An S3 origin answers a HEAD the same way.

A ranged GetObject is now recorded in CloudTrail like any other, with
the bytes of the range sent, and a range past the end of the object,
for GetObject or HeadObject, is recorded as InvalidRange.

The range parsing GetObject did is now ByteRange, which both use, and
UploadPartCopy's range stream becomes ByteRangeInputStream. GetObject
now matches the range unit in any case, as RFC 9110 section 14.1 has
it, and its InvalidRange error is the one S3 sends, as an AWS-validated
LocalStack capture records it: the message "The requested range is not
satisfiable", with no trailing period, and the RangeRequested and
ActualObjectSize fields.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-10 21:29:02 -05:00
1 parent 7d71df6ac9
commit ff20750d91
18 files changed
+785 -100

No files matched your search

@@ -28,6 +28,10 @@ import java.util.concurrent.ThreadLocalRandom;
* {@code User-Agent} is forwarded, an {@code X-Forwarded-For} ending in the viewer address,
* CloudFront's {@code Via} hop and an {@code X-Amz-Cf-Id}. {@code Host} is the origin's own
* name unless the viewer's {@code Host} is forwarded.</li>
* <li>Whatever the policies, {@code Authorization} goes with the methods CloudFront does not cache,
* {@code Content-Type} with a request body, and the viewer's {@code Range} and
* {@code If-Range} with a GET or HEAD that has a {@code Range}, since CloudFront forwards a
* range GET to the origin.</li>
* </ul>
*
* <p>This class holds no state and does no I/O. Origin custom headers are applied afterwards by the
@@ -113,6 +117,8 @@ final class CloudFrontOriginRequestBuilder {
Set<String> connectionTokens = connectionTokens(viewer.headers());
boolean forwardsAuthorization = BODY_METHODS.contains(viewer.method())
|| ("OPTIONS".equals(viewer.method()) && !forwarding.optionsCached());
boolean rangeRead = ("GET".equals(viewer.method()) || "HEAD".equals(viewer.method()))
&& viewer.headers().stream().anyMatch(header -> "range".equals(normalize(header.name())));
List<Header> headers = new ArrayList<>();
List<String> cookieHeaders = new ArrayList<>();
@@ -151,6 +157,14 @@ final class CloudFrontOriginRequestBuilder {
headers.add(header);
}
}
case "range", "if-range" -> {
// CloudFront forwards a range GET to the origin whatever the cache settings, so the
// origin can answer with the range alone. A HEAD gets them too, so it can report the
// range's length as S3's HeadObject does. If-Range only qualifies a Range.
if (rangeRead || selections.forwardsHeader(name)) {
headers.add(header);
}
}
default -> {
if (selections.forwardsHeader(name)) {
headers.add(header);
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.services.cloudfront.model.Distribution;
import io.github.hectorvent.floci.services.cloudfront.model.DistributionConfig;
import io.github.hectorvent.floci.services.cloudfront.model.Origin;
import io.github.hectorvent.floci.services.cloudfront.model.OriginAccessControl;
import io.github.hectorvent.floci.services.s3.ByteRange;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.s3.model.S3Object;
import io.quarkus.vertx.http.runtime.CurrentVertxRequest;
@@ -473,8 +474,9 @@ public class CloudFrontServingController {
}
String key = CloudFrontRequestRouter.resolveOriginKey(
origin.getOriginPath(), decodedViewerPath, config.getDefaultRootObject());
return fetchFromS3(
distribution, origin, key, viewerAuthorization, !"HEAD".equals(method));
HttpServerRequest request = currentVertxRequest.getCurrent().request();
return fetchFromS3(distribution, origin, key, viewerAuthorization, !"HEAD".equals(method),
new ViewerRange(request.getHeader("Range"), request.getHeader("If-Range")));
}
String forwardUri = CloudFrontRequestRouter.resolveForwardUri(
origin.getOriginPath(), rawViewerPath, config.getDefaultRootObject());
@@ -565,7 +567,8 @@ public class CloudFrontServingController {
Origin origin,
String key,
String viewerAuthorization,
boolean includeBody) {
boolean includeBody,
ViewerRange viewerRange) {
String bucket = CloudFrontRequestRouter.bucketFromS3Domain(origin.getDomainName());
if (bucket == null) {
return OriginResponse.error(502, "Could not determine S3 bucket for origin.");
@@ -577,14 +580,9 @@ public class CloudFrontServingController {
if (includeBody) {
// The body is streamed to the viewer, so an object of any size is served without
// being read into the heap; the metadata and the stream come from one snapshot.
S3Service.ObjectRead read = s3Service.openObject(bucket, key, null);
S3Object obj = read.object();
response = new OriginResponse(
200, contentType(obj), null, read.body(), obj.getSize(), s3ObjectHeaders(obj));
response = s3ObjectResponse(s3Service.openObject(bucket, key, null), viewerRange);
} else {
S3Object meta = s3Service.headObject(bucket, key);
response = new OriginResponse(
200, contentType(meta), null, meta.getSize(), s3ObjectHeaders(meta));
response = s3HeadResponse(s3Service.headObject(bucket, key), viewerRange);
}
} catch (AwsException e) {
response = OriginResponse.error(e.getHttpStatus(), e.getMessage());
@@ -598,6 +596,69 @@ public class CloudFrontServingController {
}
}
/**
* The GET of an S3 object, answered as S3 answers the viewer's {@code Range}: the one range it
* asks for, or 416 when that range starts past the end of the object. CloudFront serves the
* whole object, as for no {@code Range} at all, when the header is not one valid range, which
* covers several ranges, since S3 serves one range per request, and when an {@code If-Range}
* no longer describes the object.
*/
private static OriginResponse s3ObjectResponse(S3Service.ObjectRead read, ViewerRange viewerRange) {
S3Object obj = read.object();
ByteRange.Resolution resolution = resolveRange(viewerRange, obj);
return switch (resolution.outcome()) {
case PART -> {
ByteRange range = resolution.range();
Map<String, List<String>> headers = s3ObjectHeaders(obj);
putHeader(headers, "Content-Range", range.contentRange(obj.getSize()));
yield new OriginResponse(206, contentType(obj), null, range.slice(read.body()),
range.length(), headers);
}
case NOT_SATISFIABLE -> {
closeUnsent(read);
yield rangeNotSatisfiable(obj.getSize());
}
case WHOLE, INVALID -> new OriginResponse(
200, contentType(obj), null, read.body(), obj.getSize(), s3ObjectHeaders(obj));
};
}
/**
* The HEAD of an S3 object, answered as HeadObject answers a {@code Range}: "If the Range is
* satisfiable, only the ContentLength is affected in the response. If the Range is not
* satisfiable, S3 returns a 416". A header that is not one valid range is ignored, as for a GET.
*/
private static OriginResponse s3HeadResponse(S3Object meta, ViewerRange viewerRange) {
ByteRange.Resolution resolution = resolveRange(viewerRange, meta);
return switch (resolution.outcome()) {
case PART -> new OriginResponse(
200, contentType(meta), null, resolution.range().length(), s3ObjectHeaders(meta));
case NOT_SATISFIABLE -> rangeNotSatisfiable(meta.getSize());
case WHOLE, INVALID -> new OriginResponse(
200, contentType(meta), null, meta.getSize(), s3ObjectHeaders(meta));
};
}
/** The viewer's {@code Range} resolved against an object, unless its {@code If-Range} no longer matches it. */
private static ByteRange.Resolution resolveRange(ViewerRange viewerRange, S3Object obj) {
String rangeHeader = ByteRange.rangeApplies(viewerRange.ifRange(), obj.getETag(), obj.getLastModified())
? viewerRange.range() : null;
return ByteRange.resolve(rangeHeader, obj.getSize());
}
private static OriginResponse rangeNotSatisfiable(long size) {
return OriginResponse.error(416, ByteRange.NOT_SATISFIABLE_MESSAGE)
.withHeaders(Map.of("Content-Range", List.of(ByteRange.unsatisfiedContentRange(size))));
}
private static void closeUnsent(S3Service.ObjectRead read) {
try {
read.close();
} catch (IOException e) {
LOG.debugv("Could not close an unsent S3 object: {0}", e.getMessage());
}
}
private void authorizeS3OriginRead(
Distribution distribution,
Origin origin,
@@ -759,6 +820,11 @@ public class CloudFrontServingController {
record ViewerBody(InputStream stream, long length) {
}
/** The viewer's {@code Range} and the {@code If-Range} that qualifies it, either one possibly absent. */
private record ViewerRange(String range, String ifRange) {
static final ViewerRange NONE = new ViewerRange(null, null);
}
private static String originAccessIdentityId(Origin origin) {
Map<String, String> config = origin.getS3OriginConfig();
String value = config != null ? config.get("OriginAccessIdentity") : null;
@@ -911,8 +977,9 @@ public class CloudFrontServingController {
OriginResponse page;
if (CloudFrontRequestRouter.isS3Origin(errOrigin)) {
String key = CloudFrontRequestRouter.resolveOriginKey(errOrigin.getOriginPath(), errNormalized, null);
// The viewer's Range is for the object it asked for, not for the page served instead.
page = fetchFromS3(
distribution, errOrigin, key, viewerAuthorization, includeBody);
distribution, errOrigin, key, viewerAuthorization, includeBody, ViewerRange.NONE);
} else {
String forwardUri = CloudFrontRequestRouter.resolveForwardUri(errOrigin.getOriginPath(), errNormalized, null);
page = fetchFromCustomOrigin(
@@ -0,0 +1,142 @@
package io.github.hectorvent.floci.services.s3;
import java.io.InputStream;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* One byte range of an object, from a {@code Range} header that asks for a single range, as RFC 9110
* section 14.1.2 defines it. {@code last} is inclusive. S3 serves one range per GET request.
*/
public record ByteRange(long first, long last) {
/**
* The message of S3's {@code InvalidRange} error as S3 sends it, which is not the wording of the
* error code table's description.
*/
public static final String NOT_SATISFIABLE_MESSAGE = "The requested range is not satisfiable";
private static final String UNIT = "bytes=";
private static final Pattern SPEC = Pattern.compile("(\\d*)-(\\d*)");
/**
* What a {@code Range} header asks of an object: a part of it, the whole of it (no header, a
* unit other than bytes, or a suffix of an empty object), a range that starts past its end, or
* something that is not one valid range, such as several ranges or a last byte before the first.
*/
public enum Outcome { PART, WHOLE, NOT_SATISFIABLE, INVALID }
/** A resolved {@code Range} header; {@code range} is set only for {@link Outcome#PART}. */
public record Resolution(Outcome outcome, ByteRange range) {
}
public ByteRange {
if (first < 0 || last < first) {
throw new IllegalArgumentException("Not a byte range: " + first + "-" + last);
}
}
public long length() {
return last - first + 1;
}
/** The {@code Content-Range} value of this range of an object of {@code size} bytes. */
public String contentRange(long size) {
return "bytes " + first + "-" + last + "/" + size;
}
/** The {@code Content-Range} value of a 416 response for an object of {@code size} bytes. */
public static String unsatisfiedContentRange(long size) {
return "bytes */" + size;
}
/**
* Whether a {@code Range} header asks for bytes, the one unit S3 serves. Range unit names are
* case-insensitive (RFC 9110, section 14.1).
*/
public static boolean inBytes(String header) {
return header != null && header.regionMatches(true, 0, UNIT, 0, UNIT.length());
}
/**
* Whether a request's {@code Range} applies to an object, given the request's {@code If-Range}:
* always without one, and otherwise when its validator still describes the object, a quoted
* entity tag equal to the object's ETag, or an HTTP-date equal to its Last-Modified.
* Any other validator, a weak or malformed one included, means the whole object is served.
*/
public static boolean rangeApplies(String ifRange, String etag, Instant lastModified) {
if (ifRange == null) {
return true;
}
String validator = ifRange.trim();
if (validator.startsWith("\"")) {
return validator.length() > 1 && validator.endsWith("\"") && validator.equals(etag);
}
Instant date;
try {
date = ZonedDateTime.parse(validator, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant();
} catch (DateTimeParseException expected) {
// Neither a quoted entity tag nor an HTTP-date, such as a weak W/ tag: it cannot match.
return false;
}
// RFC 9110 section 13.1.5 matches a date exactly, not as the "not modified since" of
// If-Unmodified-Since, so a later date gets the whole object. Last-Modified is sent to the
// second, so it is compared to the second.
return lastModified != null && lastModified.truncatedTo(ChronoUnit.SECONDS).equals(date);
}
/** This range's bytes, read from {@code whole}, a stream over the whole object, as they are needed. */
public InputStream slice(InputStream whole) {
return new ByteRangeInputStream(whole, first, length());
}
/** Resolves a {@code Range} header against an object of {@code size} bytes. */
public static Resolution resolve(String header, long size) {
if (!inBytes(header)) {
return new Resolution(Outcome.WHOLE, null);
}
Matcher matcher = SPEC.matcher(header.substring(UNIT.length()).trim());
if (!matcher.matches() || (matcher.group(1).isEmpty() && matcher.group(2).isEmpty())) {
return new Resolution(Outcome.INVALID, null);
}
long first;
long last;
if (matcher.group(1).isEmpty()) {
long suffix = position(matcher.group(2));
if (suffix == 0) {
return new Resolution(Outcome.NOT_SATISFIABLE, null);
}
if (size == 0) {
return new Resolution(Outcome.WHOLE, null);
}
first = Math.max(0, size - suffix);
last = size - 1;
} else {
first = position(matcher.group(1));
last = matcher.group(2).isEmpty() ? Long.MAX_VALUE : position(matcher.group(2));
if (last < first) {
return new Resolution(Outcome.INVALID, null);
}
last = Math.min(last, size - 1);
}
if (first >= size) {
return new Resolution(Outcome.NOT_SATISFIABLE, null);
}
return new Resolution(Outcome.PART, new ByteRange(first, last));
}
private static long position(String digits) {
try {
return Long.parseLong(digits);
} catch (NumberFormatException ignored) {
// The pattern admits digits alone, so only a position too large for a long gets here, and
// that is past the end of any object.
return Long.MAX_VALUE;
}
}
}
@@ -1,28 +1,26 @@
package io.github.hectorvent.floci.services.s3;
import io.github.hectorvent.floci.services.s3.S3Service.CopySourceRange;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
/**
* The bytes of one copy-source range, read from a stream over the whole source as they are needed.
* The first read skips to the range's first byte, so nothing of the source is touched until the
* part is about to be written, and the stream ends after the range's last byte. A source that ends
* The bytes of one range of an object, read from a stream over the whole object as they are needed.
* The first read skips to the range's first byte, so nothing of the object is touched until the
* range is about to be written, and the stream ends after the range's last byte. An object that ends
* before the range does fails the read.
*/
final class CopyRangeInputStream extends InputStream {
final class ByteRangeInputStream extends InputStream {
private final InputStream source;
private final long first;
private long remaining;
private boolean positioned;
CopyRangeInputStream(InputStream source, CopySourceRange range) {
ByteRangeInputStream(InputStream source, long first, long length) {
this.source = source;
this.first = range.first();
this.remaining = range.length();
this.first = first;
this.remaining = length;
}
@Override
@@ -46,7 +44,7 @@ final class CopyRangeInputStream extends InputStream {
}
int read = source.read(buffer, offset, (int) Math.min(length, remaining));
if (read < 0) {
throw new EOFException("Copy source ended " + remaining + " bytes before the end of the requested range");
throw new EOFException("Object ended " + remaining + " bytes before the end of the requested range");
}
remaining -= read;
return read;
@@ -360,7 +360,9 @@ public class PreSignedUrlFilter implements ContainerRequestFilter {
return requestHeaderNames.stream()
.map(name -> name.toLowerCase(Locale.ROOT))
.filter(name -> CHECKSUM_HEADERS_REQUIRING_SIGNATURE.contains(name) || name.startsWith("x-amz-meta-"))
.filter(name -> CHECKSUM_HEADERS_REQUIRING_SIGNATURE.contains(name) || name.startsWith("x-amz-meta-")
// A signed Range makes S3 require the If-Range that qualifies it to be signed too.
|| ("if-range".equals(name) && normalizedSignedHeaders.contains("range")))
.filter(name -> !normalizedSignedHeaders.contains(name))
.distinct()
.sorted()
@@ -56,10 +56,8 @@ import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
@@ -1050,8 +1048,10 @@ public class S3Controller {
}
boolean includeChecksum = "ENABLED".equalsIgnoreCase(resolveHeaderOrQueryParam(checksumMode, uriInfo, "x-amz-checksum-mode"));
if (rangeHeader != null && rangeHeader.startsWith("bytes=")) {
Response rangeResponse = handleRangeRequest(obj, read.body(), rangeHeader, overrides, includeChecksum);
if (ByteRange.inBytes(rangeHeader) && ByteRange.rangeApplies(
httpHeaders.getHeaderString("If-Range"), obj.getETag(), obj.getLastModified())) {
Response rangeResponse = handleRangeRequest(
bucket, key, obj, read.body(), rangeHeader, overrides, includeChecksum);
bodyHandedOff = rangeResponse.getEntity() instanceof StreamingOutput;
return rangeResponse;
}
@@ -1117,57 +1117,33 @@ public class S3Controller {
return resp;
}
private Response handleRangeRequest(S3Object obj, InputStream body, String rangeHeader,
ResponseHeaderOverrides overrides,
private Response handleRangeRequest(String bucket, String key, S3Object obj, InputStream body,
String rangeHeader, ResponseHeaderOverrides overrides,
boolean includeChecksum) {
long totalSize = obj.getSize();
String rangeSpec = rangeHeader.substring("bytes=".length()).trim();
long start, end;
try {
int dash = rangeSpec.indexOf('-');
if (dash < 0) {
return invalidRangeResponse(totalSize);
}
String before = rangeSpec.substring(0, dash);
String after = rangeSpec.substring(dash + 1);
if (before.isEmpty() && after.isEmpty()) {
return invalidRangeResponse(totalSize);
}
if (before.isEmpty()) {
long suffix = Long.parseLong(after);
if (suffix <= 0) {
return invalidRangeResponse(totalSize);
}
start = Math.max(0, totalSize - suffix);
end = totalSize - 1;
} else {
start = Long.parseLong(before);
end = after.isEmpty() ? totalSize - 1 : Math.min(Long.parseLong(after), totalSize - 1);
}
} catch (NumberFormatException e) {
return invalidRangeResponse(totalSize);
ByteRange.Resolution resolution = ByteRange.resolve(rangeHeader, totalSize);
if (resolution.outcome() == ByteRange.Outcome.WHOLE) {
emitCloudTrailEvent("GetObject", bucket, key, 0L, totalSize, null, null);
return fullObjectResponse(obj, body, overrides, includeChecksum);
}
if (resolution.outcome() != ByteRange.Outcome.PART) {
emitCloudTrailEvent("GetObject", bucket, key, 0L, 0L,
"InvalidRange", ByteRange.NOT_SATISFIABLE_MESSAGE);
return invalidRangeResponse(rangeHeader, totalSize);
}
if (start < 0 || start >= totalSize || start > end) {
if (totalSize == 0 && rangeSpec.startsWith("-")) {
return fullObjectResponse(obj, body, overrides, includeChecksum);
}
return invalidRangeResponse(totalSize);
}
long length = end - start + 1;
ByteRange range = resolution.range();
emitCloudTrailEvent("GetObject", bucket, key, 0L, range.length(), null, null);
StreamingOutput stream = output -> {
try (InputStream in = body) {
in.skipNBytes(start);
copyExactly(in, output, length);
try (InputStream in = range.slice(body)) {
in.transferTo(output);
}
};
var resp = Response.status(206)
.entity(stream)
.header("Content-Type", overrides.contentType() != null ? overrides.contentType() : obj.getContentType())
.header("Content-Length", length)
.header("Content-Range", "bytes " + start + "-" + end + "/" + totalSize)
.header("Content-Length", range.length())
.header("Content-Range", range.contentRange(totalSize))
.header("ETag", obj.getETag())
.header("Last-Modified", RFC_822.format(obj.getLastModified()))
.header("Accept-Ranges", "bytes");
@@ -1183,19 +1159,6 @@ public class S3Controller {
return fullObjectResponse(read.object(), read.body(), overrides, false);
}
private static void copyExactly(InputStream in, OutputStream out, long length) throws IOException {
byte[] buffer = new byte[64 * 1024];
long remaining = length;
while (remaining > 0) {
int n = in.read(buffer, 0, (int) Math.min(buffer.length, remaining));
if (n < 0) {
throw new EOFException("S3 object ended " + remaining + " bytes before the requested range");
}
out.write(buffer, 0, n);
remaining -= n;
}
}
private static void closeQuietly(Closeable closeable) {
try {
closeable.close();
@@ -1204,19 +1167,21 @@ public class S3Controller {
}
}
private Response invalidRangeResponse(long totalSize) {
private Response invalidRangeResponse(String rangeHeader, long totalSize) {
String xml = new XmlBuilder()
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
.start("Error")
.elem("Code", "InvalidRange")
.elem("Message", "The requested range is not satisfiable.")
.elem("Message", ByteRange.NOT_SATISFIABLE_MESSAGE)
.elem("RangeRequested", rangeHeader)
.elem("ActualObjectSize", totalSize)
.elem("RequestId", java.util.UUID.randomUUID().toString())
.end("Error")
.build();
return Response.status(416)
.entity(xml)
.type(MediaType.APPLICATION_XML)
.header("Content-Range", "bytes */" + totalSize)
.header("Content-Range", ByteRange.unsatisfiedContentRange(totalSize))
.build();
}
@@ -1281,16 +1246,35 @@ public class S3Controller {
return xmlErrorResponse(new AwsException("InvalidRequest",
"Request specific response headers cannot be used for anonymous GET requests.", 400));
}
// "If the Range is satisfiable, only the ContentLength is affected in the response. If the
// Range is not satisfiable, S3 returns a 416." A Range that is not one valid range is ignored.
long contentLength = obj.getSize();
boolean ranged = false;
String rangeHeader = httpHeaders.getHeaderString("Range");
if (ByteRange.inBytes(rangeHeader) && ByteRange.rangeApplies(
httpHeaders.getHeaderString("If-Range"), obj.getETag(), obj.getLastModified())) {
ByteRange.Resolution resolution = ByteRange.resolve(rangeHeader, obj.getSize());
if (resolution.outcome() == ByteRange.Outcome.PART) {
contentLength = resolution.range().length();
ranged = true;
} else if (resolution.outcome() == ByteRange.Outcome.NOT_SATISFIABLE) {
emitCloudTrailEvent("HeadObject", bucket, key, 0L, 0L,
"InvalidRange", ByteRange.NOT_SATISFIABLE_MESSAGE);
return headOnlyResponse(invalidRangeResponse(rangeHeader, obj.getSize()));
}
}
var resp = Response.ok()
.header("Content-Type", overrides.contentType() != null ? overrides.contentType() : obj.getContentType())
.header("Content-Length", obj.getSize())
.header("Content-Length", contentLength)
.header("ETag", obj.getETag())
.header("Last-Modified", RFC_822.format(obj.getLastModified()))
.header("Accept-Ranges", "bytes");
if (obj.getVersionId() != null) {
resp.header("x-amz-version-id", obj.getVersionId());
}
boolean includeChecksum = "ENABLED".equalsIgnoreCase(resolveHeaderOrQueryParam(checksumMode, uriInfo, "x-amz-checksum-mode"));
// As on a ranged GetObject, the stored checksum covers the whole object, not the range.
boolean includeChecksum = !ranged
&& "ENABLED".equalsIgnoreCase(resolveHeaderOrQueryParam(checksumMode, uriInfo, "x-amz-checksum-mode"));
appendObjectHeaders(resp, obj, overrides, includeChecksum);
emitCloudTrailEvent("HeadObject", bucket, key, 0L, obj.getSize(), null, null);
return resp.build();
@@ -4060,7 +4060,7 @@ public class S3Service implements Resettable, ResourceProvider {
"Your proposed upload exceeds the maximum allowed object size.", 400);
}
return storePart(destBucket, destKey, uploadId, partNumber,
new CopyRangeInputStream(read.body(), range), UploadChecksums.NONE,
new ByteRangeInputStream(read.body(), range.first(), range.length()), UploadChecksums.NONE,
sseCustomerHeaders.algorithm(), sseCustomerHeaders.key(), sseCustomerHeaders.keyMd5())
.getETag();
} catch (IOException e) {