Skip to content

Commit 0c63854

Browse files
committed
Add option for set cache policy based on cookie name or pattern
Fixes tempesta-tech#1544 Signed-off-by: Aleksey Mikhaylov <aym@tempesta-tech.com>
1 parent 25a420c commit 0c63854

File tree

10 files changed

+569
-125
lines changed

10 files changed

+569
-125
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Module.symvers
2323
.settings
2424
.pydevproject
2525

26+
# vscode project settings
27+
.vscode
28+
2629
# Python compiler cache files
2730
*.pyc
2831

fw/cache.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ tfw_cache_employ_req(TfwHttpReq *req)
356356
/* cache_fulfill - work as usual in cache mode. */
357357
BUG_ON(cmd != TFW_D_CACHE_FULFILL);
358358

359+
/* No cache for request due to http chain '$cache' action */
360+
if (req->cache_ctl.flags & TFW_HTTP_CC_CHAIN_NO_CACHE)
361+
return false;
362+
359363
if (req->cache_ctl.flags & TFW_HTTP_CC_NO_CACHE)
360364
/*
361365
* TODO: RFC 7234 4. "... a cache MUST NOT reuse a stored

fw/http.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4010,7 +4010,7 @@ tfw_http_hdr_split(TfwStr *hdr, TfwStr *name_out, TfwStr *val_out, bool inplace)
40104010

40114011
val_out->len += chunk->len;
40124012

4013-
/*
4013+
/*
40144014
* Skip OWS after the header value (RWS) - they must be in
40154015
* separate chunks too.
40164016
*/
@@ -5402,6 +5402,11 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, const TfwFsmData *data)
54025402
*/
54035403
req->cache_ctl.timestamp = tfw_current_timestamp();
54045404
req->jrxtstamp = jiffies;
5405+
/*
5406+
* Bypass cache if corresponding binary flag in request set
5407+
*/
5408+
if (unlikely(test_bit(TFW_HTTP_B_CHAIN_NO_CACHE, req->flags)))
5409+
req->cache_ctl.flags |= TFW_HTTP_CC_CHAIN_NO_CACHE;
54055410

54065411
/*
54075412
* Run frang checks first before any processing happen. Can't start

fw/http.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ enum {
133133
#define TFW_HTTP_CC_MAX_STALE 0x00000010
134134
#define TFW_HTTP_CC_MIN_FRESH 0x00000020
135135
#define TFW_HTTP_CC_OIFCACHED 0x00000040
136+
#define TFW_HTTP_CC_CHAIN_NO_CACHE 0x00000080
136137
/* Response only CC directives. */
137138
#define TFW_HTTP_CC_MUST_REVAL 0x00000100
138139
#define TFW_HTTP_CC_PROXY_REVAL 0x00000200
@@ -263,6 +264,8 @@ enum {
263264
TFW_HTTP_FLAGS_REQ,
264265
/* Sticky cookie is found and verified. */
265266
TFW_HTTP_B_HAS_STICKY = TFW_HTTP_FLAGS_REQ,
267+
/* Request fitted no cache cookie rule */
268+
TFW_HTTP_B_CHAIN_NO_CACHE,
266269
/* Request is non-idempotent. */
267270
TFW_HTTP_B_NON_IDEMP,
268271
/* Request stated 'Accept: text/html' header */

0 commit comments

Comments
 (0)