1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19:
20: class HttpContext extends Object
21: {
22:
23:
24: 25: 26: 27: 28: 29:
30: public function isModified($lastModified = NULL, $etag = NULL)
31: {
32: $response = $this->getResponse();
33: $request = $this->getRequest();
34:
35: if ($lastModified) {
36: $response->setHeader('Last-Modified', $response->date($lastModified));
37: }
38: if ($etag) {
39: $response->setHeader('ETag', '"' . addslashes($etag) . '"');
40: }
41:
42: $ifNoneMatch = $request->getHeader('If-None-Match');
43: if ($ifNoneMatch === '*') {
44: $match = TRUE; 45:
46: } elseif ($ifNoneMatch !== NULL) {
47: $etag = $response->getHeader('ETag');
48:
49: if ($etag == NULL || strpos(' ' . strtr($ifNoneMatch, ",\t", ' '), ' ' . $etag) === FALSE) {
50: return TRUE;
51:
52: } else {
53: $match = TRUE; 54: }
55: }
56:
57: $ifModifiedSince = $request->getHeader('If-Modified-Since');
58: if ($ifModifiedSince !== NULL) {
59: $lastModified = $response->getHeader('Last-Modified');
60: if ($lastModified != NULL && strtotime($lastModified) <= strtotime($ifModifiedSince)) {
61: $match = TRUE;
62:
63: } else {
64: return TRUE;
65: }
66: }
67:
68: if (empty($match)) {
69: return TRUE;
70: }
71:
72: $response->setCode(IHttpResponse::S304_NOT_MODIFIED);
73: return FALSE;
74: }
75:
76:
77:
78:
79:
80:
81:
82: 83: 84:
85: public function getRequest()
86: {
87: return Environment::getHttpRequest();
88: }
89:
90:
91:
92: 93: 94:
95: public function getResponse()
96: {
97: return Environment::getHttpResponse();
98: }
99:
100: }
101: