Skip to content

Commit 39bd93a

Browse files
committed
fix: handle invalid dates properly
Closes #262 Signed-off-by: flakey5 <[email protected]>
1 parent e2cbbe3 commit 39bd93a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/utils/request.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ export function parseUrl(request: Request): URL | undefined {
3030
}
3131

3232
export function parseConditionalHeaders(headers: Headers): ConditionalHeaders {
33-
const ifModifiedSince = headers.has('if-modified-since')
33+
let ifModifiedSince = headers.has('if-modified-since')
3434
? new Date(headers.get('if-modified-since')!)
3535
: undefined;
3636

3737
if (ifModifiedSince instanceof Date) {
3838
ifModifiedSince.setSeconds(ifModifiedSince.getSeconds() + 1);
39+
} else {
40+
// Invalid date
41+
ifModifiedSince = undefined;
3942
}
4043

4144
const ifMatch = headers.has('if-match')
@@ -46,10 +49,15 @@ export function parseConditionalHeaders(headers: Headers): ConditionalHeaders {
4649
? headers.get('if-none-match')!.replaceAll('"', '')
4750
: undefined;
4851

49-
const ifUnmodifiedSince = headers.has('if-unmodified-since')
52+
let ifUnmodifiedSince = headers.has('if-unmodified-since')
5053
? new Date(headers.get('if-unmodified-since')!)
5154
: undefined;
5255

56+
if (!(ifUnmodifiedSince instanceof Date)) {
57+
// Invalid date
58+
ifUnmodifiedSince = undefined;
59+
}
60+
5361
const range = headers.has('range')
5462
? parseRangeHeader(headers.get('range')!)
5563
: undefined;

0 commit comments

Comments
 (0)