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