From 7e2f9c6458f5be891fe3e31f24ed8a03e3048c83 Mon Sep 17 00:00:00 2001 From: hladu357 Date: Tue, 4 Jun 2024 15:17:08 +0200 Subject: [PATCH] check if cache enabled --- http_key_header_module.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/http_key_header_module.c b/http_key_header_module.c index fb71a86..72cc168 100644 --- a/http_key_header_module.c +++ b/http_key_header_module.c @@ -104,9 +104,10 @@ ngx_module_t ngx_http_key_header_module = static ngx_int_t ngx_http_key_header_filter(ngx_http_request_t *r ) { - if(r->loc_conf != NULL) { + if(r->loc_conf ) { ngx_http_key_header_loc_conf_t *conf = ngx_http_get_module_loc_conf(r, ngx_http_key_header_module); - if(conf->enabled) { + // enabled cahce enabled + if(conf->enabled && r->cache) { ngx_table_elt_t *h; h = ngx_list_push(&r->headers_out.headers); if(h == NULL) { @@ -114,11 +115,14 @@ ngx_http_key_header_filter(ngx_http_request_t *r ) } u_char hexKey[2 * NGX_HTTP_CACHE_KEY_LEN + 1]; + memset(hexKey, 0, sizeof(hexKey)); + ngx_hex_dump(hexKey, r->cache->key, NGX_HTTP_CACHE_KEY_LEN); h->hash = 1; + h->next = NULL; ngx_str_set(&h->key, "X-Cache-Key"); - ngx_str_set(&h->value, hexKey); + ngx_str_set(&h->value, "abcd"); } } return ngx_http_next_header_filter(r);