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