Skip to content

Commit 9b9e6c6

Browse files
authored
Merge pull request #26 from adoy/fix-precondition-precedence
Fix pre-condition precedence of If-None-Match over If-Modified-Since
2 parents 1ebc898 + e56d164 commit 9b9e6c6

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/Cache.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,6 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
7272
}
7373
}
7474

75-
// Last-Modified header and conditional GET check
76-
$lastModified = $response->getHeaderLine('Last-Modified');
77-
78-
if ($lastModified) {
79-
if (!is_integer($lastModified)) {
80-
$lastModified = strtotime($lastModified);
81-
}
82-
83-
$ifModifiedSince = $request->getHeaderLine('If-Modified-Since');
84-
85-
if ($ifModifiedSince && $lastModified <= strtotime($ifModifiedSince)) {
86-
return $response->withStatus(304);
87-
}
88-
}
89-
9075
// ETag header and conditional GET check
9176
$etag = $response->getHeader('ETag');
9277
$etag = reset($etag);
@@ -102,6 +87,22 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
10287
}
10388
}
10489

90+
91+
// Last-Modified header and conditional GET check
92+
$lastModified = $response->getHeaderLine('Last-Modified');
93+
94+
if ($lastModified) {
95+
if (!is_integer($lastModified)) {
96+
$lastModified = strtotime($lastModified);
97+
}
98+
99+
$ifModifiedSince = $request->getHeaderLine('If-Modified-Since');
100+
101+
if ($ifModifiedSince && $lastModified <= strtotime($ifModifiedSince)) {
102+
return $response->withStatus(304);
103+
}
104+
}
105+
105106
return $response;
106107
}
107108
}

0 commit comments

Comments
 (0)