blob: b549537c8e2835785e990a241e7e833fcd5065b4 [file] [log] [blame]
William Lallemand41db4602017-10-30 11:15:51 +01001/*
2 * Cache management
3 *
4 * Copyright 2017 HAProxy Technologies
5 * William Lallemand <wlallemand@haproxy.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
William Lallemand41db4602017-10-30 11:15:51 +010013#include <eb32tree.h>
William Lallemandf528fff2017-11-23 19:43:17 +010014#include <import/sha1.h>
William Lallemand41db4602017-10-30 11:15:51 +010015
William Lallemand75d93292017-11-21 20:01:24 +010016#include <types/action.h>
William Lallemand1f49a362017-11-21 20:01:26 +010017#include <types/cli.h>
William Lallemand75d93292017-11-21 20:01:24 +010018#include <types/filters.h>
19#include <types/proxy.h>
20#include <types/shctx.h>
21
William Lallemand41db4602017-10-30 11:15:51 +010022#include <proto/channel.h>
William Lallemand1f49a362017-11-21 20:01:26 +010023#include <proto/cli.h>
William Lallemand41db4602017-10-30 11:15:51 +010024#include <proto/proxy.h>
25#include <proto/hdr_idx.h>
26#include <proto/filters.h>
Willy Tarreau61c112a2018-10-02 16:43:32 +020027#include <proto/http_rules.h>
William Lallemand41db4602017-10-30 11:15:51 +010028#include <proto/proto_http.h>
29#include <proto/log.h>
30#include <proto/stream.h>
31#include <proto/stream_interface.h>
32#include <proto/shctx.h>
33
William Lallemand41db4602017-10-30 11:15:51 +010034
35#include <common/cfgparse.h>
36#include <common/hash.h>
37
38/* flt_cache_store */
39
40static const char *cache_store_flt_id = "cache store filter";
41
Willy Tarreaubafbe012017-11-24 17:34:44 +010042static struct pool_head *pool_head_cache_st = NULL;
William Lallemand4da3f8a2017-10-31 14:33:34 +010043
William Lallemand41db4602017-10-30 11:15:51 +010044struct applet http_cache_applet;
45
46struct flt_ops cache_ops;
47
48struct cache {
Willy Tarreaufd5efb52017-11-26 08:54:31 +010049 struct list list; /* cache linked list */
William Lallemand41db4602017-10-30 11:15:51 +010050 struct eb_root entries; /* head of cache entries based on keys */
Willy Tarreaufd5efb52017-11-26 08:54:31 +010051 unsigned int maxage; /* max-age */
52 unsigned int maxblocks;
53 char id[33]; /* cache name */
William Lallemand41db4602017-10-30 11:15:51 +010054};
55
56/*
57 * cache ctx for filters
58 */
59struct cache_st {
60 int hdrs_len;
61 struct shared_block *first_block;
62};
63
64struct cache_entry {
65 unsigned int latest_validation; /* latest validation date */
66 unsigned int expire; /* expiration date */
67 struct eb32_node eb; /* ebtree node used to hold the cache object */
William Lallemandf528fff2017-11-23 19:43:17 +010068 char hash[20];
William Lallemand41db4602017-10-30 11:15:51 +010069 unsigned char data[0];
70};
71
72#define CACHE_BLOCKSIZE 1024
73
74static struct list caches = LIST_HEAD_INIT(caches);
75static struct cache *tmp_cache_config = NULL;
76
William Lallemandf528fff2017-11-23 19:43:17 +010077struct cache_entry *entry_exist(struct cache *cache, char *hash)
William Lallemand4da3f8a2017-10-31 14:33:34 +010078{
79 struct eb32_node *node;
80 struct cache_entry *entry;
81
William Lallemandf528fff2017-11-23 19:43:17 +010082 node = eb32_lookup(&cache->entries, (*(unsigned int *)hash));
William Lallemand4da3f8a2017-10-31 14:33:34 +010083 if (!node)
84 return NULL;
85
86 entry = eb32_entry(node, struct cache_entry, eb);
William Lallemandf528fff2017-11-23 19:43:17 +010087
88 /* if that's not the right node */
89 if (memcmp(entry->hash, hash, sizeof(entry->hash)))
90 return NULL;
91
William Lallemand08727662017-11-21 20:01:27 +010092 if (entry->expire > now.tv_sec) {
William Lallemand4da3f8a2017-10-31 14:33:34 +010093 return entry;
William Lallemand08727662017-11-21 20:01:27 +010094 } else {
William Lallemand4da3f8a2017-10-31 14:33:34 +010095 eb32_delete(node);
William Lallemand08727662017-11-21 20:01:27 +010096 entry->eb.key = 0;
97 }
William Lallemand4da3f8a2017-10-31 14:33:34 +010098 return NULL;
99
100}
101
102static inline struct shared_context *shctx_ptr(struct cache *cache)
103{
104 return (struct shared_context *)((unsigned char *)cache - ((struct shared_context *)NULL)->data);
105}
106
William Lallemand77c11972017-10-31 20:43:01 +0100107static inline struct shared_block *block_ptr(struct cache_entry *entry)
108{
109 return (struct shared_block *)((unsigned char *)entry - ((struct shared_block *)NULL)->data);
110}
111
112
113
William Lallemand41db4602017-10-30 11:15:51 +0100114static int
115cache_store_init(struct proxy *px, struct flt_conf *f1conf)
116{
117 return 0;
118}
119
William Lallemand4da3f8a2017-10-31 14:33:34 +0100120static int
121cache_store_chn_start_analyze(struct stream *s, struct filter *filter, struct channel *chn)
122{
123 if (!(chn->flags & CF_ISRESP))
124 return 1;
125
126 if (filter->ctx == NULL) {
127 struct cache_st *st;
128
Willy Tarreaubafbe012017-11-24 17:34:44 +0100129 st = pool_alloc_dirty(pool_head_cache_st);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100130 if (st == NULL)
131 return -1;
132
133 st->hdrs_len = 0;
134 st->first_block = NULL;
135 filter->ctx = st;
136 }
137
138 register_data_filter(s, chn, filter);
139
140 return 1;
141}
142
143static int
William Lallemand49dc0482017-11-24 14:33:54 +0100144cache_store_chn_end_analyze(struct stream *s, struct filter *filter, struct channel *chn)
145{
146 struct cache_st *st = filter->ctx;
147 struct cache *cache = filter->config->conf;
148 struct shared_context *shctx = shctx_ptr(cache);
149
150 if (!(chn->flags & CF_ISRESP))
151 return 1;
152
153 /* Everything should be released in the http_end filter, but we need to do it
154 * there too, in case of errors */
155
156 if (st && st->first_block) {
157
158 shctx_lock(shctx);
159 shctx_row_dec_hot(shctx, st->first_block);
160 shctx_unlock(shctx);
161
162 }
163 if (st) {
Willy Tarreaubafbe012017-11-24 17:34:44 +0100164 pool_free(pool_head_cache_st, st);
William Lallemand49dc0482017-11-24 14:33:54 +0100165 filter->ctx = NULL;
166 }
167
168 return 1;
169}
170
171
172static int
William Lallemand4da3f8a2017-10-31 14:33:34 +0100173cache_store_http_headers(struct stream *s, struct filter *filter, struct http_msg *msg)
174{
175 struct cache_st *st = filter->ctx;
176
William Lallemand4da3f8a2017-10-31 14:33:34 +0100177 if (!(msg->chn->flags & CF_ISRESP) || !st)
178 return 1;
179
William Lallemand9d5f54d2017-11-14 14:39:22 +0100180 st->hdrs_len = msg->sov;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100181
182 return 1;
183}
184
185static int
186cache_store_http_forward_data(struct stream *s, struct filter *filter,
187 struct http_msg *msg, unsigned int len)
188{
189 struct cache_st *st = filter->ctx;
190 struct shared_context *shctx = shctx_ptr((struct cache *)filter->config->conf);
William Lallemand08727662017-11-21 20:01:27 +0100191 struct cache_entry *object;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100192 int ret;
193
194 /*
195 * We need to skip the HTTP headers first, because we saved them in the
196 * http-response action.
197 */
198 if (!(msg->chn->flags & CF_ISRESP) || !st)
199 return len;
200
201 if (!len) {
202 /* Nothing to foward */
203 ret = len;
204 }
William Lallemand10935bc2017-11-14 14:39:23 +0100205 else if (st->hdrs_len >= len) {
William Lallemand4da3f8a2017-10-31 14:33:34 +0100206 /* Forward part of headers */
207 ret = len;
208 st->hdrs_len -= len;
209 }
William Lallemand4da3f8a2017-10-31 14:33:34 +0100210 else {
William Lallemand10935bc2017-11-14 14:39:23 +0100211 /* Forward data */
Olivier Houchardcd2867a2017-11-01 13:58:21 +0100212 if (filter->ctx && st->first_block) {
213 /* disable buffering if too much data (never greater than a buffer size */
William Lallemand10935bc2017-11-14 14:39:23 +0100214 if (len - st->hdrs_len > global.tune.bufsize - global.tune.maxrewrite - st->first_block->len) {
William Lallemande1533f52017-11-14 14:39:24 +0100215 disable_cache:
William Lallemand08727662017-11-21 20:01:27 +0100216 object = (struct cache_entry *)st->first_block->data;
Olivier Houchardcd2867a2017-11-01 13:58:21 +0100217 filter->ctx = NULL; /* disable cache */
218 shctx_lock(shctx);
219 shctx_row_dec_hot(shctx, st->first_block);
William Lallemand08727662017-11-21 20:01:27 +0100220 object->eb.key = 0;
Olivier Houchardcd2867a2017-11-01 13:58:21 +0100221 shctx_unlock(shctx);
Willy Tarreaubafbe012017-11-24 17:34:44 +0100222 pool_free(pool_head_cache_st, st);
Olivier Houchardcd2867a2017-11-01 13:58:21 +0100223 } else {
William Lallemand10935bc2017-11-14 14:39:23 +0100224 /* Skip remaining headers to fill the cache */
Willy Tarreaubcbd3932018-06-06 07:13:22 +0200225 c_adv(msg->chn, st->hdrs_len);
William Lallemand10935bc2017-11-14 14:39:23 +0100226 ret = shctx_row_data_append(shctx,
Frédéric Lécaille0bec8072018-10-22 17:55:57 +0200227 st->first_block, NULL,
Willy Tarreaudda2e412018-06-07 18:08:04 +0200228 (unsigned char *)ci_head(msg->chn),
Willy Tarreau7194d3c2018-06-06 16:55:45 +0200229 MIN(ci_contig_data(msg->chn), len - st->hdrs_len));
William Lallemand10935bc2017-11-14 14:39:23 +0100230 /* Rewind the buffer to forward all data */
Willy Tarreaubcbd3932018-06-06 07:13:22 +0200231 c_rew(msg->chn, st->hdrs_len);
William Lallemandbcd91012017-11-28 11:33:02 +0100232 st->hdrs_len = 0;
William Lallemande1533f52017-11-14 14:39:24 +0100233 if (ret)
234 goto disable_cache;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100235 }
236 }
William Lallemand10935bc2017-11-14 14:39:23 +0100237 ret = len;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100238 }
239
240 if ((ret != len) ||
241 (FLT_NXT(filter, msg->chn) != FLT_FWD(filter, msg->chn) + ret))
242 task_wakeup(s->task, TASK_WOKEN_MSG);
243
244 return ret;
245}
246
247static int
248cache_store_http_end(struct stream *s, struct filter *filter,
249 struct http_msg *msg)
250{
251 struct cache_st *st = filter->ctx;
252 struct cache *cache = filter->config->conf;
253 struct shared_context *shctx = shctx_ptr(cache);
254 struct cache_entry *object;
255
256 if (!(msg->chn->flags & CF_ISRESP))
257 return 1;
258
259 if (st && st->first_block) {
260
261 object = (struct cache_entry *)st->first_block->data;
262
263 /* does not need to test if the insertion worked, if it
264 * doesn't, the blocks will be reused anyway */
265
266 shctx_lock(shctx);
William Lallemand08727662017-11-21 20:01:27 +0100267 if (eb32_insert(&cache->entries, &object->eb) != &object->eb) {
268 object->eb.key = 0;
269 }
William Lallemand4da3f8a2017-10-31 14:33:34 +0100270 /* remove from the hotlist */
William Lallemand4da3f8a2017-10-31 14:33:34 +0100271 shctx_row_dec_hot(shctx, st->first_block);
272 shctx_unlock(shctx);
273
274 }
275 if (st) {
Willy Tarreaubafbe012017-11-24 17:34:44 +0100276 pool_free(pool_head_cache_st, st);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100277 filter->ctx = NULL;
278 }
279
280 return 1;
281}
282
283 /*
284 * This intends to be used when checking HTTP headers for some
285 * word=value directive. Return a pointer to the first character of value, if
286 * the word was not found or if there wasn't any value assigned ot it return NULL
287 */
288char *directive_value(const char *sample, int slen, const char *word, int wlen)
289{
290 int st = 0;
291
292 if (slen < wlen)
293 return 0;
294
295 while (wlen) {
296 char c = *sample ^ *word;
297 if (c && c != ('A' ^ 'a'))
298 return NULL;
299 sample++;
300 word++;
301 slen--;
302 wlen--;
303 }
304
305 while (slen) {
306 if (st == 0) {
307 if (*sample != '=')
308 return NULL;
309 sample++;
310 slen--;
311 st = 1;
312 continue;
313 } else {
314 return (char *)sample;
315 }
316 }
317
318 return NULL;
319}
320
321/*
322 * Return the maxage in seconds of an HTTP response.
323 * Compute the maxage using either:
324 * - the assigned max-age of the cache
325 * - the s-maxage directive
326 * - the max-age directive
327 * - (Expires - Data) headers
328 * - the default-max-age of the cache
329 *
330 */
William Lallemand49b44532017-11-24 18:53:43 +0100331int http_calc_maxage(struct stream *s, struct cache *cache)
William Lallemand4da3f8a2017-10-31 14:33:34 +0100332{
333 struct http_txn *txn = s->txn;
334 struct hdr_ctx ctx;
335
336 int smaxage = -1;
337 int maxage = -1;
338
339
William Lallemand4da3f8a2017-10-31 14:33:34 +0100340 ctx.idx = 0;
341
342 /* loop on the Cache-Control values */
Willy Tarreau178b9872018-06-19 07:13:36 +0200343 while (http_find_header2("Cache-Control", 13, ci_head(&s->res), &txn->hdr_idx, &ctx)) {
William Lallemand4da3f8a2017-10-31 14:33:34 +0100344 char *directive = ctx.line + ctx.val;
345 char *value;
346
347 value = directive_value(directive, ctx.vlen, "s-maxage", 8);
348 if (value) {
Willy Tarreau83061a82018-07-13 11:56:34 +0200349 struct buffer *chk = get_trash_chunk();
William Lallemand4da3f8a2017-10-31 14:33:34 +0100350
351 chunk_strncat(chk, value, ctx.vlen - 8 + 1);
352 chunk_strncat(chk, "", 1);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200353 maxage = atoi(chk->area);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100354 }
355
356 value = directive_value(ctx.line + ctx.val, ctx.vlen, "max-age", 7);
357 if (value) {
Willy Tarreau83061a82018-07-13 11:56:34 +0200358 struct buffer *chk = get_trash_chunk();
William Lallemand4da3f8a2017-10-31 14:33:34 +0100359
360 chunk_strncat(chk, value, ctx.vlen - 7 + 1);
361 chunk_strncat(chk, "", 1);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200362 smaxage = atoi(chk->area);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100363 }
364 }
365
366 /* TODO: Expires - Data */
367
368
369 if (smaxage > 0)
William Lallemand49b44532017-11-24 18:53:43 +0100370 return MIN(smaxage, cache->maxage);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100371
372 if (maxage > 0)
William Lallemand49b44532017-11-24 18:53:43 +0100373 return MIN(maxage, cache->maxage);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100374
William Lallemand49b44532017-11-24 18:53:43 +0100375 return cache->maxage;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100376
377}
378
379
William Lallemanda400a3a2017-11-20 19:13:12 +0100380static void cache_free_blocks(struct shared_block *first, struct shared_block *block)
381{
Willy Tarreau5bd37fa2018-04-04 20:17:03 +0200382 struct cache_entry *object = (struct cache_entry *)block->data;
383
384 if (first == block && object->eb.key)
385 eb32_delete(&object->eb);
386 object->eb.key = 0;
William Lallemanda400a3a2017-11-20 19:13:12 +0100387}
388
William Lallemand41db4602017-10-30 11:15:51 +0100389/*
390 * This fonction will store the headers of the response in a buffer and then
391 * register a filter to store the data
392 */
393enum act_return http_action_store_cache(struct act_rule *rule, struct proxy *px,
394 struct session *sess, struct stream *s, int flags)
395{
William Lallemand4da3f8a2017-10-31 14:33:34 +0100396 struct http_txn *txn = s->txn;
397 struct http_msg *msg = &txn->rsp;
398 struct filter *filter;
399 struct hdr_ctx ctx;
400 struct shared_block *first = NULL;
William Lallemand49b44532017-11-24 18:53:43 +0100401 struct cache *cache = (struct cache *)rule->arg.act.p[0];
402 struct shared_context *shctx = shctx_ptr(cache);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100403 struct cache_entry *object;
404
405
406 /* Don't cache if the response came from a cache */
407 if ((obj_type(s->target) == OBJ_TYPE_APPLET) &&
408 s->target == &http_cache_applet.obj_type) {
409 goto out;
410 }
411
412 /* cache only HTTP/1.1 */
413 if (!(txn->req.flags & HTTP_MSGF_VER_11))
414 goto out;
415
William Lallemand18f133a2017-11-08 11:25:15 +0100416 /* does not cache if Content-Length unknown */
417 if (!(msg->flags & HTTP_MSGF_CNT_LEN))
418 goto out;
419
William Lallemand4da3f8a2017-10-31 14:33:34 +0100420 /* cache only GET method */
421 if (txn->meth != HTTP_METH_GET)
422 goto out;
423
424 /* cache only 200 status code */
425 if (txn->status != 200)
426 goto out;
427
428 /* Does not manage Vary at the moment. We will need a secondary key later for that */
429 ctx.idx = 0;
Willy Tarreau178b9872018-06-19 07:13:36 +0200430 if (http_find_header2("Vary", 4, ci_head(txn->rsp.chn), &txn->hdr_idx, &ctx))
William Lallemand4da3f8a2017-10-31 14:33:34 +0100431 goto out;
432
Willy Tarreaufaf29092017-12-21 15:59:17 +0100433 check_response_for_cacheability(s, &s->res);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100434
Willy Tarreaud4569d12017-12-22 18:03:04 +0100435 if (!(txn->flags & TX_CACHEABLE) || !(txn->flags & TX_CACHE_COOK))
William Lallemand4da3f8a2017-10-31 14:33:34 +0100436 goto out;
437
William Lallemand9d5f54d2017-11-14 14:39:22 +0100438 if ((msg->sov + msg->body_len) > (global.tune.bufsize - global.tune.maxrewrite))
William Lallemand4da3f8a2017-10-31 14:33:34 +0100439 goto out;
440
441 shctx_lock(shctx);
442
Frédéric Lécaille0bec8072018-10-22 17:55:57 +0200443 first = shctx_row_reserve_hot(shctx, NULL, sizeof(struct cache_entry) + msg->sov + msg->body_len);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100444 if (!first) {
445 shctx_unlock(shctx);
446 goto out;
447 }
448 shctx_unlock(shctx);
449
Willy Tarreau1093a452018-04-06 19:02:25 +0200450 /* the received memory is not initialized, we need at least to mark
451 * the object as not indexed yet.
452 */
453 object = (struct cache_entry *)first->data;
454 object->eb.node.leaf_p = NULL;
455 object->eb.key = 0;
456
William Lallemand4da3f8a2017-10-31 14:33:34 +0100457 /* reserve space for the cache_entry structure */
458 first->len = sizeof(struct cache_entry);
459
460 /* cache the headers in a http action because it allows to chose what
461 * to cache, for example you might want to cache a response before
462 * modifying some HTTP headers, or on the contrary after modifying
463 * those headers.
464 */
465
466 /* does not need to be locked because it's in the "hot" list,
467 * copy the headers */
Frédéric Lécaille0bec8072018-10-22 17:55:57 +0200468 if (shctx_row_data_append(shctx, first, NULL, (unsigned char *)ci_head(&s->res), msg->sov) < 0)
William Lallemand4da3f8a2017-10-31 14:33:34 +0100469 goto out;
470
471 /* register the buffer in the filter ctx for filling it with data*/
472 if (!LIST_ISEMPTY(&s->strm_flt.filters)) {
473 list_for_each_entry(filter, &s->strm_flt.filters, list) {
474 if (filter->config->id == cache_store_flt_id &&
475 filter->config->conf == rule->arg.act.p[0]) {
476 if (filter->ctx) {
477 struct cache_st *cache_ctx = filter->ctx;
Willy Tarreauc9bd34c2017-12-22 17:42:46 +0100478 struct cache_entry *old;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100479
480 cache_ctx->first_block = first;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100481
William Lallemandf528fff2017-11-23 19:43:17 +0100482 object->eb.key = (*(unsigned int *)&txn->cache_hash);
483 memcpy(object->hash, txn->cache_hash, sizeof(object->hash));
William Lallemand4da3f8a2017-10-31 14:33:34 +0100484 /* Insert the node later on caching success */
485
486 shctx_lock(shctx);
Willy Tarreauc9bd34c2017-12-22 17:42:46 +0100487
488 old = entry_exist(cache, txn->cache_hash);
489 if (old) {
490 eb32_delete(&old->eb);
491 old->eb.key = 0;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100492 }
493 shctx_unlock(shctx);
494
495 /* store latest value and expiration time */
496 object->latest_validation = now.tv_sec;
William Lallemand49b44532017-11-24 18:53:43 +0100497 object->expire = now.tv_sec + http_calc_maxage(s, cache);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100498 }
499 return ACT_RET_CONT;
500 }
501 }
502 }
503
504out:
505 /* if does not cache */
506 if (first) {
507 shctx_lock(shctx);
William Lallemand08727662017-11-21 20:01:27 +0100508 first->len = 0;
509 object->eb.key = 0;
William Lallemand4da3f8a2017-10-31 14:33:34 +0100510 shctx_row_dec_hot(shctx, first);
511 shctx_unlock(shctx);
512 }
513
William Lallemand41db4602017-10-30 11:15:51 +0100514 return ACT_RET_CONT;
515}
516
William Lallemand77c11972017-10-31 20:43:01 +0100517#define HTTP_CACHE_INIT 0
518#define HTTP_CACHE_FWD 1
519#define HTTP_CACHE_END 2
520
William Lallemandecb73b12017-11-24 14:33:55 +0100521static void http_cache_applet_release(struct appctx *appctx)
522{
523 struct cache *cache = (struct cache *)appctx->rule->arg.act.p[0];
524 struct cache_entry *cache_ptr = appctx->ctx.cache.entry;
525 struct shared_block *first = block_ptr(cache_ptr);
526
527 shctx_lock(shctx_ptr(cache));
528 shctx_row_dec_hot(shctx_ptr(cache), first);
529 shctx_unlock(shctx_ptr(cache));
530}
531
William Lallemand77c11972017-10-31 20:43:01 +0100532static void http_cache_io_handler(struct appctx *appctx)
533{
534 struct stream_interface *si = appctx->owner;
535 struct channel *res = si_ic(si);
536 struct cache *cache = (struct cache *)appctx->rule->arg.act.p[0];
537 struct cache_entry *cache_ptr = appctx->ctx.cache.entry;
538 struct shared_context *shctx = shctx_ptr(cache);
539 struct shared_block *first = block_ptr(cache_ptr);
540
541 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
542 goto out;
543
544 /* Check if the input buffer is avalaible. */
Willy Tarreauc9fa0482018-07-10 17:43:27 +0200545 if (res->buf.size == 0) {
William Lallemand77c11972017-10-31 20:43:01 +0100546 si_applet_cant_put(si);
547 goto out;
548 }
549
550 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
551 appctx->st0 = HTTP_CACHE_END;
552
553 /* buffer are aligned there, should be fine */
554 if (appctx->st0 == HTTP_CACHE_INIT) {
555 int len = first->len - sizeof(struct cache_entry);
Willy Tarreau8f9c72d2018-06-07 18:46:28 +0200556 if ((shctx_row_data_get(shctx, first, (unsigned char *)ci_tail(res), sizeof(struct cache_entry), len)) != 0) {
William Lallemanda71cd1d2017-11-24 18:53:42 +0100557 /* should never get there, because at the moment, a
558 * cache object can never be bigger than a buffer */
559 abort();
William Lallemand55e76742017-11-21 20:01:28 +0100560
William Lallemand77c11972017-10-31 20:43:01 +0100561 si_applet_cant_put(si);
562 goto out;
563 }
Willy Tarreauc9fa0482018-07-10 17:43:27 +0200564 b_add(&res->buf, len);
William Lallemand77c11972017-10-31 20:43:01 +0100565 res->total += len;
566 appctx->st0 = HTTP_CACHE_FWD;
567 }
568
569 if (appctx->st0 == HTTP_CACHE_FWD) {
570 /* eat the whole request */
Willy Tarreau178b9872018-06-19 07:13:36 +0200571 co_skip(si_oc(si), co_data(si_oc(si))); // NOTE: when disabled does not repport the correct status code
William Lallemand77c11972017-10-31 20:43:01 +0100572 res->flags |= CF_READ_NULL;
573 si_shutr(si);
574 }
575
576 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
577 si_shutw(si);
578out:
579 ;
580}
581
William Lallemand41db4602017-10-30 11:15:51 +0100582enum act_parse_ret parse_cache_store(const char **args, int *orig_arg, struct proxy *proxy,
583 struct act_rule *rule, char **err)
584{
585 struct flt_conf *fconf;
586 int cur_arg = *orig_arg;
587 rule->action = ACT_CUSTOM;
588 rule->action_ptr = http_action_store_cache;
589
590 if (!*args[cur_arg] || strcmp(args[cur_arg], "if") == 0 || strcmp(args[cur_arg], "unless") == 0) {
591 memprintf(err, "expects a cache name");
592 return ACT_RET_PRS_ERR;
593 }
594
595 /* check if a cache filter was already registered with this cache
596 * name, if that's the case, must use it. */
597 list_for_each_entry(fconf, &proxy->filter_configs, list) {
598 if (fconf->id == cache_store_flt_id && !strcmp((char *)fconf->conf, args[cur_arg])) {
599 rule->arg.act.p[0] = fconf->conf;
600 (*orig_arg)++;
601 /* filter already registered */
602 return ACT_RET_PRS_OK;
603 }
604 }
605
606 rule->arg.act.p[0] = strdup(args[cur_arg]);
607 if (!rule->arg.act.p[0]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100608 ha_alert("config: %s '%s': out of memory\n", proxy_type_str(proxy), proxy->id);
William Lallemand41db4602017-10-30 11:15:51 +0100609 err++;
610 goto err;
611 }
612 /* register a filter to fill the cache buffer */
613 fconf = calloc(1, sizeof(*fconf));
614 if (!fconf) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100615 ha_alert("config: %s '%s': out of memory\n",
616 proxy_type_str(proxy), proxy->id);
William Lallemand41db4602017-10-30 11:15:51 +0100617 err++;
618 goto err;
619 }
620 fconf->id = cache_store_flt_id;
621 fconf->conf = rule->arg.act.p[0]; /* store the proxy name */
622 fconf->ops = &cache_ops;
623 LIST_ADDQ(&proxy->filter_configs, &fconf->list);
624
625 (*orig_arg)++;
626
627 return ACT_RET_PRS_OK;
628
629err:
Olivier Houchardfccf8402017-11-01 14:04:02 +0100630 return ACT_RET_PRS_ERR;
William Lallemand41db4602017-10-30 11:15:51 +0100631}
632
William Lallemandf528fff2017-11-23 19:43:17 +0100633/* This produces a sha1 hash of the concatenation of the first
634 * occurrence of the Host header followed by the path component if it
635 * begins with a slash ('/'). */
636int sha1_hosturi(struct http_txn *txn)
637{
638 struct hdr_ctx ctx;
639
640 blk_SHA_CTX sha1_ctx;
Willy Tarreau83061a82018-07-13 11:56:34 +0200641 struct buffer *trash;
William Lallemandf528fff2017-11-23 19:43:17 +0100642 char *path;
643 char *end;
644 trash = get_trash_chunk();
645
646 /* retrive the host */
647 ctx.idx = 0;
Willy Tarreau178b9872018-06-19 07:13:36 +0200648 if (!http_find_header2("Host", 4, ci_head(txn->req.chn), &txn->hdr_idx, &ctx))
William Lallemandf528fff2017-11-23 19:43:17 +0100649 return 0;
650 chunk_strncat(trash, ctx.line + ctx.val, ctx.vlen);
651
652 /* now retrieve the path */
Willy Tarreau178b9872018-06-19 07:13:36 +0200653 end = ci_head(txn->req.chn) + txn->req.sl.rq.u + txn->req.sl.rq.u_l;
Willy Tarreau6b952c82018-09-10 17:45:34 +0200654 path = http_txn_get_path(txn);
William Lallemandf528fff2017-11-23 19:43:17 +0100655 if (!path)
656 return 0;
657 chunk_strncat(trash, path, end - path);
658
659 /* hash everything */
660 blk_SHA1_Init(&sha1_ctx);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200661 blk_SHA1_Update(&sha1_ctx, trash->area, trash->data);
William Lallemandf528fff2017-11-23 19:43:17 +0100662 blk_SHA1_Final((unsigned char *)txn->cache_hash, &sha1_ctx);
663
664 return 1;
665}
666
667
William Lallemand41db4602017-10-30 11:15:51 +0100668
669enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *px,
670 struct session *sess, struct stream *s, int flags)
671{
William Lallemand77c11972017-10-31 20:43:01 +0100672
William Lallemand77c11972017-10-31 20:43:01 +0100673 struct cache_entry *res;
William Lallemand77c11972017-10-31 20:43:01 +0100674 struct cache *cache = (struct cache *)rule->arg.act.p[0];
675
Willy Tarreau504455c2017-12-22 17:47:35 +0100676 check_request_for_cacheability(s, &s->req);
677 if ((s->txn->flags & (TX_CACHE_IGNORE|TX_CACHEABLE)) == TX_CACHE_IGNORE)
678 return ACT_RET_CONT;
679
Willy Tarreau7704b1e2017-12-22 16:32:43 +0100680 if (!sha1_hosturi(s->txn))
681 return ACT_RET_CONT;
William Lallemandf528fff2017-11-23 19:43:17 +0100682
Willy Tarreau504455c2017-12-22 17:47:35 +0100683 if (s->txn->flags & TX_CACHE_IGNORE)
684 return ACT_RET_CONT;
685
William Lallemanda400a3a2017-11-20 19:13:12 +0100686 shctx_lock(shctx_ptr(cache));
William Lallemandf528fff2017-11-23 19:43:17 +0100687 res = entry_exist(cache, s->txn->cache_hash);
William Lallemand77c11972017-10-31 20:43:01 +0100688 if (res) {
689 struct appctx *appctx;
William Lallemanda400a3a2017-11-20 19:13:12 +0100690 shctx_row_inc_hot(shctx_ptr(cache), block_ptr(res));
691 shctx_unlock(shctx_ptr(cache));
William Lallemand77c11972017-10-31 20:43:01 +0100692 s->target = &http_cache_applet.obj_type;
693 if ((appctx = stream_int_register_handler(&s->si[1], objt_applet(s->target)))) {
694 appctx->st0 = HTTP_CACHE_INIT;
695 appctx->rule = rule;
696 appctx->ctx.cache.entry = res;
Olivier Houchardfccf8402017-11-01 14:04:02 +0100697 return ACT_RET_CONT;
William Lallemand77c11972017-10-31 20:43:01 +0100698 } else {
William Lallemand55e76742017-11-21 20:01:28 +0100699 shctx_lock(shctx_ptr(cache));
700 shctx_row_dec_hot(shctx_ptr(cache), block_ptr(res));
701 shctx_unlock(shctx_ptr(cache));
Olivier Houchardfccf8402017-11-01 14:04:02 +0100702 return ACT_RET_YIELD;
William Lallemand77c11972017-10-31 20:43:01 +0100703 }
704 }
William Lallemanda400a3a2017-11-20 19:13:12 +0100705 shctx_unlock(shctx_ptr(cache));
Olivier Houchardfccf8402017-11-01 14:04:02 +0100706 return ACT_RET_CONT;
William Lallemand41db4602017-10-30 11:15:51 +0100707}
708
709
710enum act_parse_ret parse_cache_use(const char **args, int *orig_arg, struct proxy *proxy,
711 struct act_rule *rule, char **err)
712{
713 int cur_arg = *orig_arg;
714
715 rule->action = ACT_CUSTOM;
716 rule->action_ptr = http_action_req_cache_use;
717
718 if (!*args[cur_arg] || strcmp(args[cur_arg], "if") == 0 || strcmp(args[cur_arg], "unless") == 0) {
719 memprintf(err, "expects a cache name");
720 return ACT_RET_PRS_ERR;
721 }
722
723 rule->arg.act.p[0] = strdup(args[cur_arg]);
724 if (!rule->arg.act.p[0]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100725 ha_alert("config: %s '%s': out of memory\n", proxy_type_str(proxy), proxy->id);
William Lallemand41db4602017-10-30 11:15:51 +0100726 err++;
727 goto err;
728 }
729
730 (*orig_arg)++;
731 return ACT_RET_PRS_OK;
732
733err:
Olivier Houchardfccf8402017-11-01 14:04:02 +0100734 return ACT_RET_PRS_ERR;
William Lallemand41db4602017-10-30 11:15:51 +0100735
736}
737
738int cfg_parse_cache(const char *file, int linenum, char **args, int kwm)
739{
740 int err_code = 0;
741
742 if (strcmp(args[0], "cache") == 0) { /* new cache section */
743
744 if (!*args[1]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100745 ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n",
746 file, linenum, args[0]);
William Lallemand41db4602017-10-30 11:15:51 +0100747 err_code |= ERR_ALERT | ERR_ABORT;
748 goto out;
749 }
750
751 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
752 err_code |= ERR_ABORT;
753 goto out;
754 }
755
756 if (tmp_cache_config == NULL) {
757 tmp_cache_config = calloc(1, sizeof(*tmp_cache_config));
758 if (!tmp_cache_config) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100759 ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
William Lallemand41db4602017-10-30 11:15:51 +0100760 err_code |= ERR_ALERT | ERR_ABORT;
761 goto out;
762 }
763
764 strlcpy2(tmp_cache_config->id, args[1], 33);
765 if (strlen(args[1]) > 32) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100766 ha_warning("parsing [%s:%d]: cache id is limited to 32 characters, truncate to '%s'.\n",
767 file, linenum, tmp_cache_config->id);
William Lallemand41db4602017-10-30 11:15:51 +0100768 err_code |= ERR_WARN;
769 }
William Lallemand49b44532017-11-24 18:53:43 +0100770 tmp_cache_config->maxage = 60;
William Lallemand41db4602017-10-30 11:15:51 +0100771 tmp_cache_config->maxblocks = 0;
772 }
773 } else if (strcmp(args[0], "total-max-size") == 0) {
774 int maxsize;
775
776 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
777 err_code |= ERR_ABORT;
778 goto out;
779 }
780
781 /* size in megabytes */
782 maxsize = atoi(args[1]) * 1024 * 1024 / CACHE_BLOCKSIZE;
783 tmp_cache_config->maxblocks = maxsize;
784
William Lallemand49b44532017-11-24 18:53:43 +0100785 } else if (strcmp(args[0], "max-age") == 0) {
786 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
787 err_code |= ERR_ABORT;
788 goto out;
789 }
790
791 if (!*args[1]) {
792 ha_warning("parsing [%s:%d]: '%s' expects an age parameter in seconds.\n",
793 file, linenum, args[0]);
794 err_code |= ERR_WARN;
795 }
796
797 tmp_cache_config->maxage = atoi(args[1]);
William Lallemand41db4602017-10-30 11:15:51 +0100798 } else if (*args[0] != 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100799 ha_alert("parsing [%s:%d] : unknown keyword '%s' in 'cache' section\n", file, linenum, args[0]);
William Lallemand41db4602017-10-30 11:15:51 +0100800 err_code |= ERR_ALERT | ERR_FATAL;
801 goto out;
802 }
803out:
804 return err_code;
805}
806
807/* once the cache section is parsed */
808
809int cfg_post_parse_section_cache()
810{
811 struct shared_context *shctx;
812 int err_code = 0;
813 int ret_shctx;
814
815 if (tmp_cache_config) {
816 struct cache *cache;
817
818 if (tmp_cache_config->maxblocks <= 0) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100819 ha_alert("Size not specified for cache '%s'\n", tmp_cache_config->id);
William Lallemand41db4602017-10-30 11:15:51 +0100820 err_code |= ERR_FATAL | ERR_ALERT;
821 goto out;
822 }
823
824 ret_shctx = shctx_init(&shctx, tmp_cache_config->maxblocks, CACHE_BLOCKSIZE, sizeof(struct cache), 1);
William Lallemand4da3f8a2017-10-31 14:33:34 +0100825
William Lallemand41db4602017-10-30 11:15:51 +0100826 if (ret_shctx < 0) {
827 if (ret_shctx == SHCTX_E_INIT_LOCK)
Christopher Faulet767a84b2017-11-24 16:50:31 +0100828 ha_alert("Unable to initialize the lock for the cache.\n");
William Lallemand41db4602017-10-30 11:15:51 +0100829 else
Christopher Faulet767a84b2017-11-24 16:50:31 +0100830 ha_alert("Unable to allocate cache.\n");
William Lallemand41db4602017-10-30 11:15:51 +0100831
832 err_code |= ERR_FATAL | ERR_ALERT;
833 goto out;
834 }
William Lallemanda400a3a2017-11-20 19:13:12 +0100835 shctx->free_block = cache_free_blocks;
William Lallemand41db4602017-10-30 11:15:51 +0100836 memcpy(shctx->data, tmp_cache_config, sizeof(struct cache));
837 cache = (struct cache *)shctx->data;
838 cache->entries = EB_ROOT_UNIQUE;
William Lallemand41db4602017-10-30 11:15:51 +0100839 LIST_ADDQ(&caches, &cache->list);
840 }
841out:
842 free(tmp_cache_config);
843 tmp_cache_config = NULL;
844 return err_code;
845
846}
847
848/*
849 * Resolve the cache name to a pointer once the file is completely read.
850 */
851int cfg_cache_postparser()
852{
853 struct act_rule *hresrule, *hrqrule;
854 void *cache_ptr;
855 struct cache *cache;
856 struct proxy *curproxy = NULL;
857 int err = 0;
858 struct flt_conf *fconf;
859
Olivier Houchardfbc74e82017-11-24 16:54:05 +0100860 for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
William Lallemand41db4602017-10-30 11:15:51 +0100861
862 /* resolve the http response cache name to a ptr in the action rule */
863 list_for_each_entry(hresrule, &curproxy->http_res_rules, list) {
864 if (hresrule->action != ACT_CUSTOM ||
865 hresrule->action_ptr != http_action_store_cache)
866 continue;
867
868 cache_ptr = hresrule->arg.act.p[0];
869
870 list_for_each_entry(cache, &caches, list) {
871 if (!strcmp(cache->id, cache_ptr)) {
872 /* don't free there, it's still used in the filter conf */
873 cache_ptr = cache;
874 break;
875 }
876 }
877
878 if (cache_ptr == hresrule->arg.act.p[0]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100879 ha_alert("Proxy '%s': unable to find the cache '%s' referenced by http-response cache-store rule.\n",
880 curproxy->id, (char *)hresrule->arg.act.p[0]);
William Lallemand41db4602017-10-30 11:15:51 +0100881 err++;
882 }
883
884 hresrule->arg.act.p[0] = cache_ptr;
885 }
886
887 /* resolve the http request cache name to a ptr in the action rule */
888 list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) {
889 if (hrqrule->action != ACT_CUSTOM ||
890 hrqrule->action_ptr != http_action_req_cache_use)
891 continue;
892
893 cache_ptr = hrqrule->arg.act.p[0];
894
895 list_for_each_entry(cache, &caches, list) {
896 if (!strcmp(cache->id, cache_ptr)) {
897 free(cache_ptr);
898 cache_ptr = cache;
899 break;
900 }
901 }
902
903 if (cache_ptr == hrqrule->arg.act.p[0]) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100904 ha_alert("Proxy '%s': unable to find the cache '%s' referenced by http-request cache-use rule.\n",
905 curproxy->id, (char *)hrqrule->arg.act.p[0]);
William Lallemand41db4602017-10-30 11:15:51 +0100906 err++;
907 }
908
909 hrqrule->arg.act.p[0] = cache_ptr;
910 }
911
912 /* resolve the cache name to a ptr in the filter config */
913 list_for_each_entry(fconf, &curproxy->filter_configs, list) {
914
William Lallemand9c54c532017-11-02 16:38:42 +0100915 if (fconf->id != cache_store_flt_id)
916 continue;
917
William Lallemand41db4602017-10-30 11:15:51 +0100918 cache_ptr = fconf->conf;
919
920 list_for_each_entry(cache, &caches, list) {
921 if (!strcmp(cache->id, cache_ptr)) {
922 /* there can be only one filter per cache, so we free it there */
923 free(cache_ptr);
924 cache_ptr = cache;
925 break;
926 }
927 }
928
929 if (cache_ptr == fconf->conf) {
Christopher Faulet767a84b2017-11-24 16:50:31 +0100930 ha_alert("Proxy '%s': unable to find the cache '%s' referenced by the filter 'cache'.\n",
931 curproxy->id, (char *)fconf->conf);
William Lallemand41db4602017-10-30 11:15:51 +0100932 err++;
933 }
934 fconf->conf = cache_ptr;
935 }
936 }
937 return err;
938}
939
940
941struct flt_ops cache_ops = {
942 .init = cache_store_init,
943
William Lallemand4da3f8a2017-10-31 14:33:34 +0100944 /* Handle channels activity */
945 .channel_start_analyze = cache_store_chn_start_analyze,
William Lallemand49dc0482017-11-24 14:33:54 +0100946 .channel_end_analyze = cache_store_chn_end_analyze,
William Lallemand4da3f8a2017-10-31 14:33:34 +0100947
948 /* Filter HTTP requests and responses */
949 .http_headers = cache_store_http_headers,
950 .http_end = cache_store_http_end,
951
952 .http_forward_data = cache_store_http_forward_data,
953
William Lallemand41db4602017-10-30 11:15:51 +0100954};
955
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +0200956static int cli_parse_show_cache(char **args, char *payload, struct appctx *appctx, void *private)
William Lallemand1f49a362017-11-21 20:01:26 +0100957{
958 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
959 return 1;
960
961 return 0;
962}
963
964static int cli_io_handler_show_cache(struct appctx *appctx)
965{
966 struct cache* cache = appctx->ctx.cli.p0;
967 struct stream_interface *si = appctx->owner;
968
William Lallemand1f49a362017-11-21 20:01:26 +0100969 if (cache == NULL) {
970 cache = LIST_ELEM((caches).n, typeof(struct cache *), list);
971 }
972
973 list_for_each_entry_from(cache, &caches, list) {
974 struct eb32_node *node = NULL;
975 unsigned int next_key;
976 struct cache_entry *entry;
977
William Lallemand1f49a362017-11-21 20:01:26 +0100978 next_key = appctx->ctx.cli.i0;
Willy Tarreauafe1de52018-04-04 11:56:43 +0200979 if (!next_key) {
980 chunk_printf(&trash, "%p: %s (shctx:%p, available blocks:%d)\n", cache, cache->id, shctx_ptr(cache), shctx_ptr(cache)->nbav);
981 if (ci_putchk(si_ic(si), &trash) == -1) {
982 si_applet_cant_put(si);
983 return 0;
984 }
985 }
William Lallemand1f49a362017-11-21 20:01:26 +0100986
987 appctx->ctx.cli.p0 = cache;
988
989 while (1) {
990
991 shctx_lock(shctx_ptr(cache));
992 node = eb32_lookup_ge(&cache->entries, next_key);
993 if (!node) {
994 shctx_unlock(shctx_ptr(cache));
Willy Tarreauafe1de52018-04-04 11:56:43 +0200995 appctx->ctx.cli.i0 = 0;
William Lallemand1f49a362017-11-21 20:01:26 +0100996 break;
997 }
998
999 entry = container_of(node, struct cache_entry, eb);
Willy Tarreauafe1de52018-04-04 11:56:43 +02001000 chunk_printf(&trash, "%p hash:%u size:%u (%u blocks), refcount:%u, expire:%d\n", entry, (*(unsigned int *)entry->hash), block_ptr(entry)->len, block_ptr(entry)->block_count, block_ptr(entry)->refcount, entry->expire - (int)now.tv_sec);
William Lallemand1f49a362017-11-21 20:01:26 +01001001
1002 next_key = node->key + 1;
1003 appctx->ctx.cli.i0 = next_key;
1004
1005 shctx_unlock(shctx_ptr(cache));
1006
1007 if (ci_putchk(si_ic(si), &trash) == -1) {
1008 si_applet_cant_put(si);
1009 return 0;
1010 }
1011 }
1012
1013 }
1014
1015 return 1;
1016
1017}
1018
1019static struct cli_kw_list cli_kws = {{},{
William Lallemande899af82017-11-22 16:41:26 +01001020 { { "show", "cache", NULL }, "show cache : show cache status", cli_parse_show_cache, cli_io_handler_show_cache, NULL, NULL },
1021 {{},}
William Lallemand1f49a362017-11-21 20:01:26 +01001022}};
1023
1024
William Lallemand41db4602017-10-30 11:15:51 +01001025static struct action_kw_list http_res_actions = {
1026 .kw = {
1027 { "cache-store", parse_cache_store },
1028 { NULL, NULL }
1029 }
1030};
1031
1032static struct action_kw_list http_req_actions = {
1033 .kw = {
1034 { "cache-use", parse_cache_use },
1035 { NULL, NULL }
1036 }
1037};
1038
1039struct applet http_cache_applet = {
1040 .obj_type = OBJ_TYPE_APPLET,
1041 .name = "<CACHE>", /* used for logging */
William Lallemand77c11972017-10-31 20:43:01 +01001042 .fct = http_cache_io_handler,
William Lallemandecb73b12017-11-24 14:33:55 +01001043 .release = http_cache_applet_release,
William Lallemand41db4602017-10-30 11:15:51 +01001044};
1045
1046__attribute__((constructor))
1047static void __cache_init(void)
1048{
1049 cfg_register_section("cache", cfg_parse_cache, cfg_post_parse_section_cache);
1050 cfg_register_postparser("cache", cfg_cache_postparser);
William Lallemand1f49a362017-11-21 20:01:26 +01001051 cli_register_kw(&cli_kws);
William Lallemand41db4602017-10-30 11:15:51 +01001052 http_res_keywords_register(&http_res_actions);
1053 http_req_keywords_register(&http_req_actions);
Willy Tarreaubafbe012017-11-24 17:34:44 +01001054 pool_head_cache_st = create_pool("cache_st", sizeof(struct cache_st), MEM_F_SHARED);
William Lallemand41db4602017-10-30 11:15:51 +01001055}
1056