mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): keep Content-Encoding and Cache-Control on multipart uploads (#7000)
* fix(s3): keep Content-Encoding and Cache-Control on multipart uploads CreateMultipartUpload ignored both headers, so an object completed from a multipart upload came back from HeadObject and GetObject without them while a single PutObject kept them. A client that decodes by Content-Encoding (a browser, curl --compressed) then received raw gzip bytes for any object large enough to be uploaded in parts. The controller now reads both headers on the ?uploads branch, stripping the aws-chunked token as PutObject does. S3Service records them on the MultipartUpload and applies them to the object when the upload completes. An upload created without either header still produces an object with neither. * test(s3): use .bin keys and text/plain in the multipart encoding tests Match the neighbouring tests, which name objects *.bin; the behaviour under test is not specific to YAML. The content type is text/plain rather than application/octet-stream because MultipartUpload falls back to application/octet-stream when CreateMultipartUpload carries no Content-Type, so asserting that value could not catch a dropped header. --------- Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
This commit is contained in:
1 parent
ca3599f8c9
commit
55c33d7ad3
7 files changed
+132
-3
No files matched your search
@@ -2,6 +2,8 @@ package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Checksum;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.config.DecoderConfig;
|
||||
import io.restassured.config.RestAssuredConfig;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
@@ -215,6 +217,8 @@ class S3MultipartIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Disposition", equalTo("attachment; filename=\"multipart.bin\""))
|
||||
.header("Content-Encoding", nullValue())
|
||||
.header("Cache-Control", nullValue())
|
||||
.header("x-amz-server-side-encryption", equalTo("AES256"))
|
||||
.header("x-amz-meta-owner", equalTo("team-a"))
|
||||
.header("x-amz-storage-class", equalTo("STANDARD_IA"))
|
||||
@@ -1559,6 +1563,60 @@ class S3MultipartIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(40)
|
||||
void completedObjectKeepsContentEncodingAndCacheControl() {
|
||||
String key = "encoded-multipart.bin";
|
||||
String encodedUploadId = given()
|
||||
.header("Content-Type", "text/plain")
|
||||
.header("Content-Encoding", "gzip,aws-chunked")
|
||||
.header("Cache-Control", "no-cache")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
|
||||
String eTag = given()
|
||||
.body(PART_1)
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + key + "?uploadId=" + encodedUploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().header("ETag");
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body(singlePartCompleteXml(eTag, ""))
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploadId=" + encodedUploadId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<CompleteMultipartUploadResult"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.head("/" + BUCKET + "/" + key)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Encoding", equalTo("gzip"))
|
||||
.header("Cache-Control", equalTo("no-cache"))
|
||||
// RestAssured appends a default charset to the Content-Type it sends
|
||||
.header("Content-Type", startsWith("text/plain"));
|
||||
|
||||
RestAssuredConfig noDecompress = RestAssuredConfig.config()
|
||||
.decoderConfig(DecoderConfig.decoderConfig().noContentDecoders());
|
||||
given()
|
||||
.config(noDecompress)
|
||||
.when()
|
||||
.get("/" + BUCKET + "/" + key)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Encoding", equalTo("gzip"))
|
||||
.header("Cache-Control", equalTo("no-cache"))
|
||||
.body(equalTo(PART_1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(41)
|
||||
void cleanUp() {
|
||||
given().when().delete("/" + BUCKET + "/copy-of-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/" + KEY).then().statusCode(204);
|
||||
@@ -1577,6 +1635,7 @@ class S3MultipartIntegrationTest {
|
||||
given().when().delete("/" + BUCKET + "/range-source.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/one-part-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/one-part-composite.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/encoded-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET).then().statusCode(204);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.services.s3.model.GetObjectAttributesResult;
|
||||
import io.github.hectorvent.floci.services.s3.model.MultipartUpload;
|
||||
import io.github.hectorvent.floci.services.s3.model.ObjectAttributeName;
|
||||
import io.github.hectorvent.floci.services.s3.model.Part;
|
||||
import io.github.hectorvent.floci.services.s3.model.PutObjectOptions;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Checksum;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -347,6 +348,19 @@ class S3MultipartServiceTest {
|
||||
assertTrue(s3Service.getObjectTagging("test-bucket", "untagged.bin").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void completeMultipartUploadAppliesContentEncodingAndCacheControl() {
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload("test-bucket", "encoded.bin", "text/plain",
|
||||
null, null, new PutObjectOptions().withContentEncoding("gzip").withCacheControl("no-cache"));
|
||||
s3Service.uploadPart("test-bucket", "encoded.bin", upload.getUploadId(), 1, "part1".getBytes());
|
||||
|
||||
s3Service.completeMultipartUpload("test-bucket", "encoded.bin", upload.getUploadId(), List.of(1), null, null);
|
||||
|
||||
S3Object object = s3Service.headObject("test-bucket", "encoded.bin");
|
||||
assertEquals("gzip", object.getContentEncoding());
|
||||
assertEquals("no-cache", object.getCacheControl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void completeMultipartUploadMissingPart() {
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload("test-bucket", "file.bin", null);
|
||||
|
||||
Reference in new issue
Block a user