From 9fbccb305a5b1c7c38eac4c8336cb81dac4fcfe0 Mon Sep 17 00:00:00 2001 From: flakey5 <73616808+flakey5@users.noreply.github.com> Date: Mon, 3 Mar 2025 13:16:23 -0800 Subject: [PATCH] fix: don't return 412 for if-none-match failures Closes nodejs/build#4030 Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com> --- src/providers/r2Provider.ts | 9 +++------ tests/e2e/file.test.ts | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/providers/r2Provider.ts b/src/providers/r2Provider.ts index 00c1faa..226178a 100644 --- a/src/providers/r2Provider.ts +++ b/src/providers/r2Provider.ts @@ -180,13 +180,10 @@ function areConditionalHeadersPresent( const { conditionalHeaders } = options; - // Only check for if-none-match and if-unmodified-since because the docs said + // Only check for if-unmodified-since because the docs said // so, also what nginx does from my experiments // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/412 - return ( - conditionalHeaders.ifNoneMatch !== undefined || - conditionalHeaders.ifUnmodifiedSince !== undefined - ); + return conditionalHeaders.ifUnmodifiedSince !== undefined; } function determineHttpStatusCode( @@ -208,7 +205,7 @@ function determineHttpStatusCode( return 412; } - // We weren't given a body and preconditions succeeded. + // We weren't given a body return 304; } diff --git a/tests/e2e/file.test.ts b/tests/e2e/file.test.ts index 9a5fb40..ef2aec5 100644 --- a/tests/e2e/file.test.ts +++ b/tests/e2e/file.test.ts @@ -160,7 +160,7 @@ describe('File Tests', () => { 'if-none-match': originalETag, }, }); - assert(res.status === 304 || res.status === 412); + assert(res.status === 304); }); it('handles range header correctly', async () => {