Skip to content

Commit 0f63a03

Browse files
MeAkibalan-agius4
authored andcommitted
fix(@angular/build): quote weak ETags of assets served by the dev server
Extensionless, JavaScript, TypeScript and stylesheet assets served by the dev server and the Vitest browser runner sent an unquoted weak ETag such as `W/25a71cd345af2de4`. RFC 9110 requires the entity tag to be quoted (`W/"25a71cd345af2de4"`), which is how the other ETags in the same middleware are already formatted. (cherry picked from commit 0e2799d)
1 parent 9e8eea0 commit 0f63a03

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

‎packages/angular/build/src/builders/dev-server/tests/behavior/build-assets_spec.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupT
3939

4040
expect(result?.success).toBeTrue();
4141
expect(await response?.text()).toContain(javascriptFileContent);
42+
expect(response?.headers.get('ETag')).toMatch(/^W\/"[^"]+"$/);
4243
});
4344

4445
it('serves a project JavaScript asset unmodified', async () => {

‎packages/angular/build/src/tools/vite/middlewares/assets-middleware.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function createAngularAssetsMiddleware(
5050
// This is a workaround to serve extensionless, CSS, JS and TS files without Vite transformations.
5151
if (!extension || JS_TS_REGEXP.test(extension) || CSS_PREPROCESSOR_REGEXP.test(extension)) {
5252
const contents = readFileSync(asset.source);
53-
const etag = `W/${calculateHash(contents)}`;
53+
const etag = `W/"${calculateHash(contents)}"`;
5454
if (checkAndHandleEtag(req, res, etag)) {
5555
return;
5656
}
@@ -238,7 +238,7 @@ export function createBuildAssetsMiddleware(
238238
const contents =
239239
outputFile.origin === 'memory' ? outputFile.contents : readHandler(outputFile.inputPath);
240240

241-
const etag = `W/${calculateHash(contents)}`;
241+
const etag = `W/"${calculateHash(contents)}"`;
242242
if (checkAndHandleEtag(req, res, etag)) {
243243
return;
244244
}

0 commit comments

Comments
 (0)