@ -348,28 +348,29 @@ module.exports = class CachePolicy {
} ;
} ;
}
}
validationRequest ( req ) {
validationRequest ( incoming_ req) {
this . _ assertRequestHasHeaders ( req ) ;
this . _ assertRequestHasHeaders ( incoming_ req) ;
if ( ! ( this . _ resHeaders . etag || this . _ resHeaders [ "last-modified" ] ) ) {
if ( ! this . _ resHeaders . etag && ! this . _ resHeaders [ "last-modified" ] ) {
return null ; // no validators available
return incoming_req ; // no validators available
}
}
// revalidation allowed via HEAD
// revalidation allowed via HEAD
if ( ! this . _ requestMatches ( req , true ) ) {
if ( ! this . _ requestMatches ( incoming_ req, true ) ) {
return null ; // not for the same resource
return incoming_req ; // not for the same resource
}
}
const vreq = Object . assign ( { } , req ) ;
vreq . headers = Object . assign ( { } , req . headers ) ;
const upstream_req = Object . assign ( { } , incoming_req ) ;
upstream_req . headers = Object . assign ( { } , incoming_req . headers ) ;
/* MUST send that entity-tag in any cache validation request (using If-Match or If-None-Match) if an entity-tag has been provided by the origin server. */
/* MUST send that entity-tag in any cache validation request (using If-Match or If-None-Match) if an entity-tag has been provided by the origin server. */
if ( this . _ resHeaders . etag ) {
if ( this . _ resHeaders . etag ) {
v req. headers [ 'if-none-match' ] = this . _ resHeaders . etag ;
upstream_ req. headers [ 'if-none-match' ] = this . _ resHeaders . etag ;
}
}
/ * S H O U L D s e n d t h e L a s t - M o d i f i e d v a l u e i n n o n - s u b r a n g e c a c h e v a l i d a t i o n r e q u e s t s ( u s i n g I f - M o d i f i e d - S i n c e ) i f o n l y a L a s t - M o d i f i e d v a l u e h a s b e e n p r o v i d e d b y t h e o r i g i n s e r v e r .
/ * S H O U L D s e n d t h e L a s t - M o d i f i e d v a l u e i n n o n - s u b r a n g e c a c h e v a l i d a t i o n r e q u e s t s ( u s i n g I f - M o d i f i e d - S i n c e ) i f o n l y a L a s t - M o d i f i e d v a l u e h a s b e e n p r o v i d e d b y t h e o r i g i n s e r v e r .
Note : This implementation does not understand partial responses ( 206 ) * /
Note : This implementation does not understand partial responses ( 206 ) * /
if ( this . _ resHeaders [ 'last-modified' ] ) {
if ( this . _ resHeaders [ 'last-modified' ] && this . storable ( ) ) {
v req. headers [ 'if-modified-since' ] = this . _ resHeaders [ 'last-modified' ] ;
upstream_ req. headers [ 'if-modified-since' ] = this . _ resHeaders [ 'last-modified' ] ;
}
}
return v req;
return upstream_ req;
}
}
} ;
} ;