mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): honor response-* query parameters on GetObject and HeadObject (#923)
Per the S3 API, six query parameters override response headers on GetObject and HeadObject (presigned URLs are the canonical use case): response-content-type, response-content-language, response-expires, response-cache-control, response-content-disposition, response-content-encoding. Floci previously ignored them and emitted only the values stored on the object at upload time. Adds the six @QueryParam bindings, threads them through getObject, headObject, and handleRangeRequest, and lets them win over stored values when present. Empty query values are normalized to null to match AWS behavior of ignoring empty response-* overrides. Routing range responses through appendObjectHeaders also closes a pre-existing gap where 206 responses dropped stored Content-Disposition / Cache-Control / Content-Encoding and version-id headers. Closes #916
This commit is contained in:
1 parent
6a9af6057c
commit
d89270c538
2 files changed
+192
-17
No files matched your search
+117
-1
@@ -118,11 +118,127 @@ class PreSignedUrlIntegrationTest {
|
||||
.body(equalTo("uploaded via presigned PUT"));
|
||||
}
|
||||
|
||||
// --- response-* query parameter overrides on presigned GET/HEAD ---
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(10)
|
||||
void uploadObjectWithStoredHeadersForOverrideTests() {
|
||||
given()
|
||||
.body("override-content")
|
||||
.contentType("text/plain")
|
||||
.header("Content-Disposition", "inline")
|
||||
.header("Cache-Control", "max-age=60")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/disposition-file.txt")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void getObjectAppliesResponseContentDispositionOverride() {
|
||||
// Stored disposition is "inline"; override should win.
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.when()
|
||||
.get("/" + BUCKET + "/disposition-file.txt?response-content-disposition=attachment%3B%20filename%3D%22file.txt%22")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Disposition", equalTo("attachment; filename=\"file.txt\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void getObjectAppliesAllResponseOverrides() {
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.when()
|
||||
.get("/" + BUCKET + "/disposition-file.txt"
|
||||
+ "?response-content-type=application%2Fpdf"
|
||||
+ "&response-content-language=en-US"
|
||||
+ "&response-expires=Thu%2C%2001%20Dec%202099%2016%3A00%3A00%20GMT"
|
||||
+ "&response-cache-control=no-store"
|
||||
+ "&response-content-disposition=attachment"
|
||||
+ "&response-content-encoding=identity")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Type", equalTo("application/pdf"))
|
||||
.header("Content-Language", equalTo("en-US"))
|
||||
.header("Expires", equalTo("Thu, 01 Dec 2099 16:00:00 GMT"))
|
||||
.header("Cache-Control", equalTo("no-store"))
|
||||
.header("Content-Disposition", equalTo("attachment"))
|
||||
.header("Content-Encoding", equalTo("identity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void getObjectWithoutOverridesReturnsStoredHeaders() {
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "/disposition-file.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Disposition", equalTo("inline"))
|
||||
.header("Cache-Control", equalTo("max-age=60"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void headObjectAppliesResponseContentDispositionOverride() {
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.when()
|
||||
.head("/" + BUCKET + "/disposition-file.txt?response-content-disposition=attachment%3B%20filename%3D%22head.txt%22")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Disposition", equalTo("attachment; filename=\"head.txt\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void emptyResponseOverrideIsIgnoredAndFallsBackToStored() {
|
||||
// `?response-content-disposition=` binds as "" in JAX-RS; real S3 treats it as absent.
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.when()
|
||||
.get("/" + BUCKET + "/disposition-file.txt?response-content-disposition=")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Content-Disposition", equalTo("inline"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void rangeRequestAppliesResponseContentDispositionOverride() {
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.header("Range", "bytes=0-3")
|
||||
.when()
|
||||
.get("/" + BUCKET + "/disposition-file.txt?response-content-disposition=attachment%3B%20filename%3D%22range.txt%22")
|
||||
.then()
|
||||
.statusCode(206)
|
||||
.header("Content-Disposition", equalTo("attachment; filename=\"range.txt\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void rangeRequestWithoutOverrideFallsBackToStoredDisposition() {
|
||||
given()
|
||||
.header("Range", "bytes=0-3")
|
||||
.when()
|
||||
.get("/" + BUCKET + "/disposition-file.txt")
|
||||
.then()
|
||||
.statusCode(206)
|
||||
.header("Content-Disposition", equalTo("inline"))
|
||||
.header("Cache-Control", equalTo("max-age=60"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanUp() {
|
||||
given().when().delete("/" + BUCKET + "/secret-file.txt").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/uploaded-via-presign.txt").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/disposition-file.txt").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET).then().statusCode(204);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user