]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compression/filters: Initialize the comp filter when stream is created
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Mar 2020 13:59:05 +0000 (14:59 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Mar 2020 14:36:04 +0000 (15:36 +0100)
Since the HTX mode is the only mode to process HTTP messages, the stream is
created for a uniq transaction. The keep-alive is handled at the mux level. So,
the compression filter can be initialized when the stream is created and
released with the stream. Concretly, .channel_start_analyze and
.channel_end_analyze callback functions are replaced by .attach and .detach
ones.

With this change, it is no longer necessary to call FLT_START_FE/BE and FLT_END
analysers for the compression filter.

src/flt_http_comp.c

index b456fcd7a4afe29bd3fba8519545552887863a93..dc7898472b1ae501b68d3564a1697aa4032ac729 100644 (file)
@@ -87,44 +87,39 @@ comp_flt_deinit_per_thread(struct proxy *px, struct flt_conf *fconf)
 }
 
 static int
-comp_start_analyze(struct stream *s, struct filter *filter, struct channel *chn)
+comp_strm_init(struct stream *s, struct filter *filter)
 {
+       struct comp_state *st;
 
-       if (filter->ctx == NULL) {
-               struct comp_state *st;
-
-               st = pool_alloc_dirty(pool_head_comp_state);
-               if (st == NULL)
-                       return -1;
+       st = pool_alloc_dirty(pool_head_comp_state);
+       if (st == NULL)
+               return -1;
 
-               st->comp_algo = NULL;
-               st->comp_ctx  = NULL;
-               filter->ctx   = st;
-
-               /* Register post-analyzer on AN_RES_WAIT_HTTP because we need to
-                * analyze response headers before http-response rules execution
-                * to be sure we can use res.comp and res.comp_algo sample
-                * fetches */
-               filter->post_analyzers |= AN_RES_WAIT_HTTP;
-       }
+       st->comp_algo = NULL;
+       st->comp_ctx  = NULL;
+       filter->ctx   = st;
+
+       /* Register post-analyzer on AN_RES_WAIT_HTTP because we need to
+        * analyze response headers before http-response rules execution
+        * to be sure we can use res.comp and res.comp_algo sample
+        * fetches */
+       filter->post_analyzers |= AN_RES_WAIT_HTTP;
        return 1;
 }
 
-static int
-comp_end_analyze(struct stream *s, struct filter *filter, struct channel *chn)
+static void
+comp_strm_deinit(struct stream *s, struct filter *filter)
 {
        struct comp_state *st = filter->ctx;
 
        if (!st)
-               goto end;
+               return;
 
        /* release any possible compression context */
        if (st->comp_algo)
                st->comp_algo->end(&st->comp_ctx);
        pool_free(pool_head_comp_state, st);
        filter->ctx = NULL;
- end:
-       return 1;
 }
 
 static int
@@ -617,8 +612,9 @@ struct flt_ops comp_ops = {
        .init_per_thread   = comp_flt_init_per_thread,
        .deinit_per_thread = comp_flt_deinit_per_thread,
 
-       .channel_start_analyze = comp_start_analyze,
-       .channel_end_analyze   = comp_end_analyze,
+       .attach = comp_strm_init,
+       .detach = comp_strm_deinit,
+
        .channel_post_analyze  = comp_http_post_analyze,
 
        .http_headers          = comp_http_headers,