From: Remi Tricot-Le Breton Date: Wed, 23 Dec 2020 17:13:44 +0000 (+0100) Subject: MINOR: cache: Refactoring of secondary_key building functions X-Git-Tag: v2.4-dev5~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bba2912758c3820190daa5a42bd25362ef6c0b24;p=thirdparty%2Fhaproxy.git MINOR: cache: Refactoring of secondary_key building functions The two secondary_key building functions (prebuild_full_key and build_key) have roughly the same content so their code can be mutualized. --- diff --git a/src/cache.c b/src/cache.c index 705ed446cd..8ef41b2992 100644 --- a/src/cache.c +++ b/src/cache.c @@ -2120,33 +2120,9 @@ static int default_normalizer(struct ist value, char *buf, unsigned int *buf_len */ static int http_request_prebuild_full_secondary_key(struct stream *s) { - struct http_txn *txn = s->txn; - struct htx *htx = htxbuf(&s->req.buf); - struct http_hdr_ctx ctx = { .blk = NULL }; - - unsigned int idx; - const struct vary_hashing_information *info = NULL; - unsigned int hash_length = 0; - int retval = 0; - int offset = 0; - - for (idx = 0; idx < sizeof(vary_information)/sizeof(*vary_information) && !retval; ++idx) { - info = &vary_information[idx]; - - ctx.blk = NULL; - if (info->norm_fn != NULL && http_find_header(htx, info->hdr_name, &ctx, 1)) { - retval = info->norm_fn(ctx.value, &txn->cache_secondary_hash[offset], &hash_length); - offset += hash_length; - } - else { - /* Fill hash with 0s. */ - hash_length = info->hash_length; - memset(&txn->cache_secondary_hash[offset], 0, hash_length); - offset += hash_length; - } - } - - return retval; + /* The fake signature (second parameter) will ensure that every part of the + * secondary key is calculated. */ + return http_request_build_secondary_key(s, ~0); } @@ -2176,8 +2152,7 @@ static int http_request_build_secondary_key(struct stream *s, int vary_signature info = &vary_information[idx]; ctx.blk = NULL; - if ((vary_signature & info->value) && info->norm_fn != NULL && - http_find_header(htx, info->hdr_name, &ctx, 1)) { + if (info->norm_fn != NULL && http_find_header(htx, info->hdr_name, &ctx, 1)) { retval = info->norm_fn(ctx.value, &txn->cache_secondary_hash[offset], &hash_length); offset += hash_length; }