From: Christopher Faulet Date: Fri, 6 Mar 2020 13:59:05 +0000 (+0100) Subject: MINOR: compression/filters: Initialize the comp filter when stream is created X-Git-Tag: v2.2-dev4~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e896510a8ea8a429fc3d68a31d3288562f7fa63;p=thirdparty%2Fhaproxy.git MINOR: compression/filters: Initialize the comp filter when stream is created 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. --- diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index b456fcd7a4..dc7898472b 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -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,