Skip to content

Commit

Permalink
Add option for set cache policy based on cookie name or pattern (temp…
Browse files Browse the repository at this point in the history
…esta-tech#1564)

Fixes tempesta-tech#1544

Signed-off-by: Aleksey Mikhaylov <aym@tempesta-tech.com>
  • Loading branch information
ttaym authored Feb 18, 2022
1 parent bb12aab commit abc9c21
Show file tree
Hide file tree
Showing 10 changed files with 605 additions and 133 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Module.symvers
.settings
.pydevproject

# vscode project settings
.vscode

# Python compiler cache files
*.pyc

Expand Down
1 change: 1 addition & 0 deletions fw/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ tfw_cache_employ_req(TfwHttpReq *req)
/* cache_fulfill - work as usual in cache mode. */
BUG_ON(cmd != TFW_D_CACHE_FULFILL);

/* CC_NO_CACHE also may be set by http chain rules */
if (req->cache_ctl.flags & TFW_HTTP_CC_NO_CACHE)
/*
* TODO: RFC 7234 4. "... a cache MUST NOT reuse a stored
Expand Down
8 changes: 8 additions & 0 deletions fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -5412,6 +5412,14 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, const TfwFsmData *data)
*/
req->cache_ctl.timestamp = tfw_current_timestamp();
req->jrxtstamp = jiffies;
/*
* Bypass cache if corresponding binary flag in request set.
* We need separate from cache_ctl binary flag in request
* due to multiple rules may one after one set and clear
* the flag before it evaluated to CC_NO_CACHE here.
*/
if (unlikely(test_bit(TFW_HTTP_B_CHAIN_NO_CACHE, req->flags)))
req->cache_ctl.flags |= TFW_HTTP_CC_NO_CACHE;

/*
* Run frang checks first before any processing happen. Can't start
Expand Down
2 changes: 2 additions & 0 deletions fw/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ enum {
TFW_HTTP_FLAGS_REQ,
/* Sticky cookie is found and verified. */
TFW_HTTP_B_HAS_STICKY = TFW_HTTP_FLAGS_REQ,
/* Request fitted no cache cookie rule */
TFW_HTTP_B_CHAIN_NO_CACHE,
/* Request is non-idempotent. */
TFW_HTTP_B_NON_IDEMP,
/* Request stated 'Accept: text/html' header */
Expand Down
Loading

0 comments on commit abc9c21

Please sign in to comment.