Skip to content

Commit c491b6e

Browse files
author
eduardo
committed
Add Content-Disposition header for proxied images
1 parent bb760aa commit c491b6e

2 files changed

Lines changed: 292 additions & 16 deletions

File tree

api_tests/src/image.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ afterAll(async () => {
4040
await Promise.allSettled([unfollows(), deleteAllMedia(alpha)]);
4141
});
4242

43+
function inlineContentDisposition(filename: string): string {
44+
return `inline; filename="${filename}"`;
45+
}
46+
47+
function filenameFromUrl(url: string): string {
48+
return decodeURIComponent(new URL(url).pathname.split("/").pop() ?? "");
49+
}
50+
4351
test("Upload image and delete it", async () => {
4452
const health = await alpha.imageHealth();
4553
expect(health.success).toBeTruthy();
@@ -166,6 +174,8 @@ test("Purge post, linked image removed", async () => {
166174
});
167175

168176
test("Images in remote image post are proxied if setting enabled", async () => {
177+
const expectedFilename = filenameFromUrl(sampleImage);
178+
169179
let community = await createCommunity(gamma);
170180
let postRes = await createPost(
171181
gamma,
@@ -192,6 +202,14 @@ test("Images in remote image post are proxied if setting enabled", async () => {
192202
// Make sure that it contains `jpg`, to be sure its an image
193203
expect(post.thumbnail_url?.includes(".jpg")).toBeTruthy();
194204

205+
// Proxied image should include a Content-Disposition: inline header
206+
if (post.thumbnail_url) {
207+
const proxyResponse = await fetch(post.thumbnail_url);
208+
const cd = proxyResponse.headers.get("content-disposition");
209+
expect(cd).not.toBeNull();
210+
expect(cd).toBe(inlineContentDisposition(expectedFilename));
211+
}
212+
195213
let epsilonPostRes = await resolvePost(epsilon, postRes.post_view.post);
196214
expect(epsilonPostRes?.post).toBeDefined();
197215

@@ -216,6 +234,13 @@ test("Images in remote image post are proxied if setting enabled", async () => {
216234

217235
// Make sure that it contains `jpg`, to be sure its an image
218236
expect(epsilonPost.thumbnail_url?.includes(".jpg")).toBeTruthy();
237+
238+
if (epsilonPost.thumbnail_url) {
239+
const proxyResponse = await fetch(epsilonPost.thumbnail_url);
240+
const cd = proxyResponse.headers.get("content-disposition");
241+
expect(cd).not.toBeNull();
242+
expect(cd).toBe(inlineContentDisposition(expectedFilename));
243+
}
219244
});
220245

221246
test("Thumbnail of remote image link is proxied if setting enabled", async () => {

0 commit comments

Comments
 (0)