44import {
55 compareStrong ,
66 compareWeak ,
7+ isErr ,
78 isString ,
8- isValidDate ,
99 parseETag ,
1010 parseHttpDate ,
11+ unsafe ,
1112} from "../deps.ts" ;
1213import { parse } from "../if_match.ts" ;
1314
@@ -50,18 +51,21 @@ export function ifModifiedSince(
5051 fieldValue : string ,
5152 lastModified : string ,
5253) : boolean {
53- const date = parseHttpDate ( fieldValue ) ;
54+ const dateContainer = unsafe ( ( ) => parseHttpDate ( fieldValue ) ) ;
5455
55- if ( ! isValidDate ( date ) ) {
56+ if ( isErr ( dateContainer ) ) {
5657 throw SyntaxError ( Msg . InvalidField ) ;
5758 }
5859
59- const lastMod = parseHttpDate ( lastModified ) ;
60+ const date = dateContainer . value ;
61+ const lastModContainer = unsafe ( ( ) => parseHttpDate ( lastModified ) ) ;
6062
61- if ( ! isValidDate ( lastMod ) ) {
63+ if ( isErr ( lastModContainer ) ) {
6264 throw SyntaxError ( Msg . InvalidLastModified ) ;
6365 }
6466
67+ const lastMod = lastModContainer . value ;
68+
6569 // The origin server SHOULD NOT perform the requested
6670 // method if the selected representation's last modification date is
6771 // earlier than or equal to the date provided in the field-value;
@@ -75,18 +79,21 @@ export function ifUnmodifiedSince(
7579 fieldValue : string ,
7680 lastModified : string ,
7781) : boolean {
78- const date = parseHttpDate ( fieldValue ) ;
82+ const dateContainer = unsafe ( ( ) => parseHttpDate ( fieldValue ) ) ;
7983
80- if ( ! isValidDate ( date ) ) {
84+ if ( isErr ( dateContainer ) ) {
8185 throw SyntaxError ( Msg . InvalidField ) ;
8286 }
8387
84- const lastMod = parseHttpDate ( lastModified ) ;
88+ const lastModContainer = unsafe ( ( ) => parseHttpDate ( lastModified ) ) ;
8589
86- if ( ! isValidDate ( lastMod ) ) {
90+ if ( isErr ( lastModContainer ) ) {
8791 throw SyntaxError ( Msg . InvalidLastModified ) ;
8892 }
8993
94+ const date = dateContainer . value ;
95+ const lastMod = lastModContainer . value ;
96+
9097 // The origin server MUST NOT perform the requested method
9198 // if the selected representation's last modification date is more
9299 // recent than the date provided in the field-value;
@@ -114,18 +121,21 @@ export function ifRange(fieldValue: string, headers: IfRangeHeaders): boolean {
114121
115122 if ( ! isString ( lastModified ) ) throw Error ( ) ;
116123
117- const left = parseHttpDate ( fieldValue ) ;
124+ const leftContainer = unsafe ( ( ) => parseHttpDate ( fieldValue ) ) ;
118125
119- if ( ! isValidDate ( left ) ) {
126+ if ( isErr ( leftContainer ) ) {
120127 throw SyntaxError ( Msg . InvalidField ) ;
121128 }
122129
123- const right = parseHttpDate ( lastModified ) ;
130+ const rightContainer = unsafe ( ( ) => parseHttpDate ( lastModified ) ) ;
124131
125- if ( ! isValidDate ( right ) ) {
132+ if ( isErr ( rightContainer ) ) {
126133 throw SyntaxError ( Msg . InvalidLastModified ) ;
127134 }
128135
136+ const left = leftContainer . value ;
137+ const right = rightContainer . value ;
138+
129139 return left . getTime ( ) === right . getTime ( ) ;
130140}
131141
0 commit comments