@@ -2,9 +2,10 @@ import { IncomingHttpHeaders, OutgoingHttpHeaders } from "node:http";
22
33/**
44 * RegExp to check for no-cache token in Cache-Control.
5+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#max-age_2
56 * @private
67 */
7- const CACHE_CONTROL_NO_CACHE_REGEXP = / (?: ^ | , ) \s * ?n o - c a c h e \s * ?(?: , | $ ) / ;
8+ const CACHE_CONTROL_NO_CACHE_REGEXP = / (?: ^ | , ) \s * ?(?: n o - c a c h e | m a x - a g e = 0 ) \s * ?(?: , | $ ) / ;
89
910/**
1011 * Parse an HTTP Date into a number.
@@ -28,25 +29,30 @@ function compareETags(etag: string, str: string): boolean {
2829 * @private
2930 */
3031function isStale ( etag : string , noneMatch : string ) : boolean {
32+ const length = noneMatch . length ;
3133 let start = 0 ;
3234 let end = 0 ;
3335
34- for ( let i = 0 , len = noneMatch . length ; i < len ; i ++ ) {
36+ for ( let i = 0 ; i < length ; i ++ ) {
3537 switch ( noneMatch . charCodeAt ( i ) ) {
3638 case 0x20 : /* */
3739 if ( start === end ) start = end = i + 1 ;
40+
3841 break ;
3942 case 0x2c : /* , */
40- if ( compareETags ( etag , noneMatch . substring ( start , end ) ) ) return false ;
43+ if ( compareETags ( etag , noneMatch . slice ( start , end ) ) ) return false ;
44+
4145 start = end = i + 1 ;
46+
4247 break ;
4348 default :
4449 end = i + 1 ;
50+
4551 break ;
4652 }
4753 }
4854
49- return ! compareETags ( etag , noneMatch . substring ( start , end ) ) ;
55+ return ! compareETags ( etag , noneMatch . slice ( start , end ) ) ;
5056}
5157
5258/**
@@ -81,10 +87,7 @@ export default function fresh(
8187 if ( modifiedSince ) {
8288 const lastModified = resHeaders [ "last-modified" ] as string | undefined ;
8389
84- if (
85- ! lastModified
86- || ! ( parseHttpDate ( lastModified ) <= parseHttpDate ( modifiedSince ) )
87- ) return false ;
90+ if ( ! lastModified || ! ( parseHttpDate ( lastModified ) <= parseHttpDate ( modifiedSince ) ) ) return false ;
8891 }
8992
9093 return true ;
0 commit comments