@@ -933,8 +933,11 @@ static int http_check_vary_header(struct htx *htx, unsigned int *vary_signature)
933933 * Look for the accept-encoding part of the secondary_key and replace the
934934 * encoding bitmap part of the hash with the actual encoding of the response,
935935 * extracted from the content-encoding header value.
936+ * Responses that have an unknown encoding will not be cached if they also
937+ * "vary" on the accept-encoding value.
938+ * Returns 0 if we found a known encoding in the response, -1 otherwise.
936939 */
937- static void set_secondary_key_encoding (struct htx * htx , char * secondary_key )
940+ static int set_secondary_key_encoding (struct htx * htx , char * secondary_key )
938941{
939942 unsigned int resp_encoding_bitmap = 0 ;
940943 const struct vary_hashing_information * info = vary_information ;
@@ -952,13 +955,12 @@ static void set_secondary_key_encoding(struct htx *htx, char *secondary_key)
952955 }
953956
954957 if (count == hash_info_count )
955- return ;
958+ return -1 ;
956959
957960 while (http_find_header (htx , ist ("content-encoding" ), & ctx , 0 )) {
958- if (!parse_encoding_value (ctx .value , & encoding_value , NULL ))
959- resp_encoding_bitmap |= encoding_value ;
960- else
961- resp_encoding_bitmap |= VARY_ENCODING_OTHER ;
961+ if (parse_encoding_value (ctx .value , & encoding_value , NULL ))
962+ return -1 ; /* Do not store responses with an unknown encoding */
963+ resp_encoding_bitmap |= encoding_value ;
962964 }
963965
964966 if (!resp_encoding_bitmap )
@@ -967,6 +969,8 @@ static void set_secondary_key_encoding(struct htx *htx, char *secondary_key)
967969 /* Rewrite the bitmap part of the hash with the new bitmap that only
968970 * corresponds the the response's encoding. */
969971 write_u32 (secondary_key + offset , resp_encoding_bitmap );
972+
973+ return 0 ;
970974}
971975
972976
@@ -1197,9 +1201,12 @@ enum act_return http_action_store_cache(struct act_rule *rule, struct proxy *px,
11971201 /* If the response has a secondary_key, fill its key part related to
11981202 * encodings with the actual encoding of the response. This way any
11991203 * subsequent request having the same primary key will have its accepted
1200- * encodings tested upon the cached response's one. */
1204+ * encodings tested upon the cached response's one.
1205+ * We will not cache a response that has an unknown encoding (not
1206+ * explicitely supported in parse_encoding_value function). */
12011207 if (cache -> vary_processing_enabled && vary_signature )
1202- set_secondary_key_encoding (htx , object -> secondary_key );
1208+ if (set_secondary_key_encoding (htx , object -> secondary_key ))
1209+ goto out ;
12031210
12041211 shctx_lock (shctx );
12051212 if (!shctx_row_reserve_hot (shctx , first , trash .data )) {
0 commit comments