Skip to content

Add option for set cache policy based on cookie name or pattern #1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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