- Favor early return over a `retval` variable and `break` in a loop.
- Avoid the use of `else`.
- Remove useless comparison with `1` / `0`.
---
 src/cache.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/src/cache.c b/src/cache.c
index a5e26c330..9564158fc 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1138,11 +1138,8 @@ int sha1_hosturi(struct stream *s)
 static int should_send_notmodified_response(struct cache *cache, struct htx 
*htx,
                                             struct cache_entry *entry)
 {
-       int retval = 0;
-
        struct http_hdr_ctx ctx = { .blk = NULL };
        struct ist cache_entry_etag = IST_NULL;
-       struct buffer *etag_buffer = NULL;
 
        if (entry->etag_length == 0)
                return 0;
@@ -1151,35 +1148,30 @@ static int should_send_notmodified_response(struct 
cache *cache, struct htx *htx
         * cache_entry's ETag in order to perform comparisons. */
        /* There could be multiple "if-none-match" header lines. */
        while (http_find_header(htx, ist("if-none-match"), &ctx, 0)) {
-
                /* A '*' matches everything. */
-               if (isteq(ctx.value, ist("*")) != 0) {
-                       retval = 1;
-                       break;
-               }
+               if (isteq(ctx.value, ist("*")))
+                       return 1;
 
                /* Rebuild the stored ETag. */
-               if (etag_buffer == NULL) {
-                       etag_buffer = get_trash_chunk();
+               if (!isttest(cache_entry_etag)) {
+                       struct buffer *etag_buffer = get_trash_chunk();
 
                        if (shctx_row_data_get(shctx_ptr(cache), 
block_ptr(entry),
                                               (unsigned 
char*)b_orig(etag_buffer),
-                                              entry->etag_offset, 
entry->etag_length) == 0) {
-                               cache_entry_etag = ist2(b_orig(etag_buffer), 
entry->etag_length);
-                       } else {
+                                              entry->etag_offset, 
entry->etag_length) != 0) {
                                /* We could not rebuild the ETag in one go, we
                                 * won't send a "304 Not Modified" response. */
-                               break;
+                               return 0;
                        }
+                       
+                       cache_entry_etag = ist2(b_orig(etag_buffer), 
entry->etag_length);
                }
 
-               if (http_compare_etags(cache_entry_etag, ctx.value) == 1) {
-                       retval = 1;
-                       break;
-               }
+               if (http_compare_etags(cache_entry_etag, ctx.value))
+                       return 1;
        }
 
-       return retval;
+       return 0;
 }
 
 enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy 
*px,
-- 
2.29.0


Reply via email to