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