34 public function setValidators( $eTag, $lastModified, $hasRepresentation ) {
36 if ( $lastModified ===
null ) {
37 $this->lastModified =
null;
39 $this->lastModified = (int)ConvertibleTimestamp::convert( TS_UNIX, $lastModified );
41 $this->hasRepresentation = $hasRepresentation ?? ( $eTag !== null );
64 if ( $this->eTag !==
null ) {
65 $resourceTag = $parser->
parseETag( $this->eTag );
66 if ( !$resourceTag ) {
67 throw new RuntimeException(
'Invalid ETag returned by handler: `' .
68 $parser->getLastError() .
'`' );
73 $getOrHead = in_array( $request->
getMethod(), [
'GET',
'HEAD' ] );
74 if ( $request->
hasHeader(
'If-Match' ) ) {
77 foreach ( $parser->parseHeaderList( $im ) as $tag ) {
78 if ( ( $tag[
'whole'] ===
'*' && $this->hasRepresentation ) ||
79 $this->strongCompare( $resourceTag, $tag )
88 } elseif ( $request->
hasHeader(
'If-Unmodified-Since' ) ) {
90 if ( $requestDate !==
null
91 && ( $this->lastModified ===
null || $this->lastModified > $requestDate )
96 if ( $request->
hasHeader(
'If-None-Match' ) ) {
97 $inm = $request->
getHeader(
'If-None-Match' );
98 foreach ( $parser->parseHeaderList( $inm ) as $tag ) {
99 if ( ( $tag[
'whole'] ===
'*' && $this->hasRepresentation ) ||
100 $this->weakCompare( $resourceTag, $tag )
102 return $getOrHead ? 304 : 412;
105 } elseif ( $getOrHead && $request->
hasHeader(
'If-Modified-Since' ) ) {
107 if ( $requestDate !==
null && $this->lastModified !==
null
108 && $this->lastModified <= $requestDate