From c42f960af63c904e4cbb3c17ad9a5960d7ae4ef8 Mon Sep 17 00:00:00 2001 From: Le Vivilet <72156503+levivilet@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:22:17 +0100 Subject: [PATCH] feature: use generateEtag function (#283) --- .../src/parts/HandleIndexHtml/HandleIndexHtml.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/preview-process/src/parts/HandleIndexHtml/HandleIndexHtml.ts b/packages/preview-process/src/parts/HandleIndexHtml/HandleIndexHtml.ts index c381828..3491068 100644 --- a/packages/preview-process/src/parts/HandleIndexHtml/HandleIndexHtml.ts +++ b/packages/preview-process/src/parts/HandleIndexHtml/HandleIndexHtml.ts @@ -1,8 +1,8 @@ -import { createHash } from 'node:crypto' import type { HandlerOptions } from '../HandlerOptions/HandlerOptions.ts' import type { RequestOptions } from '../RequestOptions/RequestOptions.ts' import * as CrossOriginEmbedderPolicy from '../CrossOriginEmbedderPolicy/CrossOriginEmbedderPolicy.ts' import * as CrossOriginResourcePolicy from '../CrossOriginResourcePolicy/CrossOriginResourcePolicy.ts' +import * as GenerateEtag from '../GenerateEtag/GenerateEtag.ts' import * as GetContentSecurityPolicyDocument from '../GetContentSecurityPolicyDocument/GetContentSecurityPolicyDocument.ts' import * as GetContentType from '../GetContentType/GetContentType.ts' import * as HttpHeader from '../HttpHeader/HttpHeader.ts' @@ -10,12 +10,6 @@ import * as MatchesEtag from '../MatchesEtag/MatchesEtag.ts' import { NotModifiedResponse } from '../Responses/NotModifiedResponse.ts' import { ServerErrorResponse } from '../Responses/ServerErrorResponse.ts' -const generateEtag = (content: string): string => { - const hash = createHash('sha1') - hash.update(content) - return `W/"${hash.digest('hex')}"` -} - export const handleIndexHtml = async (request: RequestOptions, options: HandlerOptions): Promise => { try { if (!options.iframeContent) { @@ -32,7 +26,7 @@ export const handleIndexHtml = async (request: RequestOptions, options: HandlerO } if (options.etag) { - const etag = generateEtag(options.iframeContent) + const etag = GenerateEtag.generateEtag(options.iframeContent) if (MatchesEtag.matchesEtag(request, etag)) { return new NotModifiedResponse(etag, headers) }