BUG/MINOR: cache/htx: Make maxage calculation HTX aware

The function http_calc_maxage() was not updated to be HTX aware. So the header
"Cache-Control" on the response was never parsed to find "max-age" or "s-maxage"
values.

This patch must be backported to 2.0 and 1.9.
This commit is contained in:
Christopher Faulet 2019-07-15 20:49:46 +02:00
parent 7b889cb387
commit 5f2c49f5ee

View File

@ -578,13 +578,42 @@ char *directive_value(const char *sample, int slen, const char *word, int wlen)
*/ */
int http_calc_maxage(struct stream *s, struct cache *cache) int http_calc_maxage(struct stream *s, struct cache *cache)
{ {
struct http_txn *txn = s->txn;
struct hdr_ctx ctx;
int smaxage = -1; int smaxage = -1;
int maxage = -1; int maxage = -1;
if (IS_HTX_STRM(s)) {
/* HTX mode */
struct htx *htx = htxbuf(&s->res.buf);
struct http_hdr_ctx ctx = { .blk = NULL };
while (http_find_header(htx, ist("cache-control"), &ctx, 0)) {
char *value;
value = directive_value(ctx.value.ptr, ctx.value.len, "s-maxage", 8);
if (value) {
struct buffer *chk = get_trash_chunk();
chunk_strncat(chk, value, ctx.value.len - 8 + 1);
chunk_strncat(chk, "", 1);
maxage = atoi(chk->area);
}
value = directive_value(ctx.value.ptr, ctx.value.len, "max-age", 7);
if (value) {
struct buffer *chk = get_trash_chunk();
chunk_strncat(chk, value, ctx.value.len - 7 + 1);
chunk_strncat(chk, "", 1);
smaxage = atoi(chk->area);
}
}
}
else {
/* Legacy mode */
struct http_txn *txn = s->txn;
struct hdr_ctx ctx;
ctx.idx = 0; ctx.idx = 0;
/* loop on the Cache-Control values */ /* loop on the Cache-Control values */
@ -610,6 +639,7 @@ int http_calc_maxage(struct stream *s, struct cache *cache)
smaxage = atoi(chk->area); smaxage = atoi(chk->area);
} }
} }
}
/* TODO: Expires - Data */ /* TODO: Expires - Data */