Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

const FORMAT_PRIORITY = ['webp', 'avif', 'jpeg', 'png', 'heif', 'tiff', 'raw', 'gif'];
const FORMAT_PRIORITY = ['avif', 'webp', 'jpeg', 'png', 'heif', 'tiff', 'raw', 'gif'];

const FORMAT_MAPPING = {
'image/webp': 'webp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ exports[`ImageProcessingStack Snapshot Test 1`] = `
"FunctionCode": "// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

const FORMAT_PRIORITY = ['webp', 'avif', 'jpeg', 'png', 'heif', 'tiff', 'raw', 'gif'];
const FORMAT_PRIORITY = ['avif', 'webp', 'jpeg', 'png', 'heif', 'tiff', 'raw', 'gif'];

const FORMAT_MAPPING = {
'image/webp': 'webp',
Expand Down
2 changes: 1 addition & 1 deletion source/constructs/lib/v8/test/unit/dit-function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe("DIT CloudFront Function", () => {
describe("Accept header normalization", () => {
test("should select highest priority format from Accept header", async () => {
const testCases = [
{ input: "image/avif,image/webp,image/png", expected: "image/webp" },
{ input: "image/avif,image/webp,image/png", expected: "image/avif" },
{ input: "image/png,image/jpeg", expected: "image/jpeg" },
{ input: "image/avif,image/heif", expected: "image/avif" },
{ input: "image/gif", expected: "image/gif" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('applyAutoOptimizations', () => {
});
});

it('should prioritize formats by priority order (webp, avif, jpeg, png)', () => {
it('should prioritize formats by priority order (avif, webp, jpeg, png)', () => {
mockPolicy.outputs = [{ type: 'format', value: 'auto' }];
mockRequest.headers = { 'dit-accept': 'image/jpeg,image/avif,image/avif,*/*' };

Expand All @@ -56,6 +56,17 @@ describe('applyAutoOptimizations', () => {
expect(result[0].value).toBe('avif');
});

it('should prefer avif over webp when both are accepted', () => {
mockPolicy.outputs = [{ type: 'format', value: 'auto' }];
mockRequest.headers = { 'dit-accept': 'image/avif,image/webp' };
const imageRequest = { sourceImageContentType: 'image/jpeg' } as ImageProcessingRequest;

const result = applyAutoOptimizations(baseTransformations, mockRequest as Request, mockPolicy, imageRequest);

expect(result).toHaveLength(1);
expect(result[0]).toEqual({ type: 'format', value: 'avif', source: 'auto' });
});

it('should apply static format when policy format is not auto', () => {
mockPolicy.outputs = [{ type: 'format', value: 'jpeg' }];
mockRequest.headers = { 'dit-accept': 'image/webp,*/*' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Request } from 'express';
import { Transformation, TransformationPolicy } from '../../../types/transformation';
import { ImageProcessingRequest } from '../../../types/image-processing-request';

const FORMAT_PRIORITY = ['webp', 'avif', 'jpeg', 'png', 'heif', 'tiff', 'raw', 'gif'];
const FORMAT_PRIORITY = ['avif', 'webp', 'jpeg', 'png', 'heif', 'tiff', 'raw', 'gif'];
// TODO, DISCUSS WITH TEAM FOR OPTIMAL FORMAT PRIORITIY LIST
Comment on lines +8 to 9
const ANIMATION_CAPABLE_FORMATS = new Set(['webp', 'avif', 'gif']);
const FORMAT_MAPPING: Record<string, string> = {
Expand Down