Skip to content

Commit

Permalink
Add option for set cache policy based on cookie name or pattern
Browse files Browse the repository at this point in the history
Fixes tempesta-tech#1544

Signed-off-by: Aleksey Mikhaylov <[email protected]>
  • Loading branch information
ttaym committed Feb 16, 2022
1 parent 25a420c commit 79ad820
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 125 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
4 changes: 4 additions & 0 deletions fw/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ tfw_cache_employ_req(TfwHttpReq *req)
/* cache_fulfill - work as usual in cache mode. */
BUG_ON(cmd != TFW_D_CACHE_FULFILL);

/* No cache for request due to http chain '$cache' action */
if (req->cache_ctl.flags & TFW_HTTP_CC_CHAIN_NO_CACHE)
return false;

if (req->cache_ctl.flags & TFW_HTTP_CC_NO_CACHE)
/*
* TODO: RFC 7234 4. "... a cache MUST NOT reuse a stored
Expand Down
7 changes: 6 additions & 1 deletion fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -4010,7 +4010,7 @@ tfw_http_hdr_split(TfwStr *hdr, TfwStr *name_out, TfwStr *val_out, bool inplace)

val_out->len += chunk->len;

/*
/*
* Skip OWS after the header value (RWS) - they must be in
* separate chunks too.
*/
Expand Down Expand Up @@ -5402,6 +5402,11 @@ 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
*/
if (unlikely(test_bit(TFW_HTTP_B_CHAIN_NO_CACHE, req->flags)))
req->cache_ctl.flags |= TFW_HTTP_CC_CHAIN_NO_CACHE;

/*
* Run frang checks first before any processing happen. Can't start
Expand Down
3 changes: 3 additions & 0 deletions fw/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ enum {
#define TFW_HTTP_CC_MAX_STALE 0x00000010
#define TFW_HTTP_CC_MIN_FRESH 0x00000020
#define TFW_HTTP_CC_OIFCACHED 0x00000040
#define TFW_HTTP_CC_CHAIN_NO_CACHE 0x00000080
/* Response only CC directives. */
#define TFW_HTTP_CC_MUST_REVAL 0x00000100
#define TFW_HTTP_CC_PROXY_REVAL 0x00000200
Expand Down Expand Up @@ -263,6 +264,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 79ad820

Please sign in to comment.