Skip to content

Commit

Permalink
New file_cache and gzip filters config: "dont_cache_queries" (disable…
Browse files Browse the repository at this point in the history
…s caching for requests with ?query_string).
  • Loading branch information
yarosla committed Nov 18, 2015
1 parent b290584 commit edf0171
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib/filters/file_cache_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
typedef struct nxweb_filter_file_cache {
nxweb_filter base;
const char* cache_dir;
_Bool dont_cache_queries:1;
} nxweb_filter_file_cache;

typedef union nxf_data {
Expand Down Expand Up @@ -419,6 +420,7 @@ void _nxweb_fc_finalize(fc_filter_data* fcdata) {
}

static nxweb_filter_data* fc_init(nxweb_filter* filter, nxweb_http_server_connection* conn, nxweb_http_request* req, nxweb_http_response* resp) {
if (((nxweb_filter_file_cache*)filter)->dont_cache_queries && strchr(req->uri, '?')) return 0; // bypass requests with query string
nxweb_filter_data* fdata=nxb_calloc_obj(req->nxb, sizeof(nxweb_filter_data));
fdata->fcache=_nxweb_fc_create(req->nxb, ((nxweb_filter_file_cache*)filter)->cache_dir);
return fdata;
Expand Down Expand Up @@ -615,6 +617,7 @@ static nxweb_filter* fc_config(nxweb_filter* base, const nx_json* json) {
nxweb_filter_file_cache* f=calloc(1, sizeof(nxweb_filter_file_cache)); // NOTE this will never be freed
*f=*(nxweb_filter_file_cache*)base;
f->cache_dir=nx_json_get(json, "cache_dir")->text_value;
f->dont_cache_queries=nx_json_get(json, "dont_cache_queries")->int_value!=0;
return (nxweb_filter*)f;
}

Expand Down
7 changes: 6 additions & 1 deletion src/lib/filters/gzip_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct nxweb_filter_gzip {
nxweb_filter base;
// compression level is between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all
int compression_level;
_Bool dont_cache_queries:1;
const char* cache_dir;
} nxweb_filter_gzip;

Expand Down Expand Up @@ -272,7 +273,10 @@ static nxweb_filter_data* gzip_init(nxweb_filter* filter, nxweb_http_server_conn
gdata->rb.data_in.super.cls.os_cls=&gzip_data_in_class;
gdata->rb.data_in.ready=1;
// gdata->rb.data_out.ready=1;
if (((nxweb_filter_gzip*)filter)->cache_dir) gdata->fdata.fcache=_nxweb_fc_create(req->nxb, ((nxweb_filter_gzip*)filter)->cache_dir);
if (((nxweb_filter_gzip*)filter)->cache_dir) {
if (!(((nxweb_filter_gzip*)filter)->dont_cache_queries && strchr(req->uri, '?'))) // do not cache requests with query string
gdata->fdata.fcache=_nxweb_fc_create(req->nxb, ((nxweb_filter_gzip*)filter)->cache_dir);
}
return &gdata->fdata;
}

Expand Down Expand Up @@ -359,6 +363,7 @@ static nxweb_filter* gzip_config(nxweb_filter* base, const nx_json* json) {
*f=*(nxweb_filter_gzip*)base;
f->cache_dir=nx_json_get(json, "cache_dir")->text_value;
f->compression_level=(int)nx_json_get(json, "compression")->int_value;
f->dont_cache_queries=nx_json_get(json, "dont_cache_queries")->int_value!=0;
return (nxweb_filter*)f;
}

Expand Down

0 comments on commit edf0171

Please sign in to comment.