diff --git a/include/proto/filters.h b/include/proto/filters.h index dd7490fc0..e4061a73d 100644 --- a/include/proto/filters.h +++ b/include/proto/filters.h @@ -34,6 +34,10 @@ #define CHN_IDX(chn) (((chn)->flags & CF_ISRESP) == CF_ISRESP) #define FLT_NXT(flt, chn) ((flt)->next[CHN_IDX(chn)]) #define FLT_FWD(flt, chn) ((flt)->fwd[CHN_IDX(chn)]) +#define flt_req_nxt(flt) ((flt)->next[0]) +#define flt_rsp_nxt(flt) ((flt)->next[1]) +#define flt_req_fwd(flt) ((flt)->fwd[0]) +#define flt_rsp_fwd(flt) ((flt)->fwd[1]) #define HAS_FILTERS(strm) ((strm)->strm_flt.flags & STRM_FLT_FL_HAS_FILTERS) @@ -181,7 +185,8 @@ flt_change_next_size(struct filter *filter, struct channel *chn, int len) list_for_each_entry(f, &strm_flt(s)->filters, list) { if (f == filter) break; - FLT_NXT(f, chn) += len; + if (IS_DATA_FILTER(filter, chn)) + FLT_NXT(f, chn) += len; } } @@ -205,9 +210,11 @@ flt_change_forward_size(struct filter *filter, struct channel *chn, int len) list_for_each_entry(f, &strm_flt(s)->filters, list) { if (f == filter) before = 0; - if (before) - FLT_FWD(f, chn) += len; - FLT_NXT(f, chn) += len; + if (IS_DATA_FILTER(filter, chn)) { + if (before) + FLT_FWD(f, chn) += len; + FLT_NXT(f, chn) += len; + } } } diff --git a/include/types/filters.h b/include/types/filters.h index 38f96d9ca..c433078bd 100644 --- a/include/types/filters.h +++ b/include/types/filters.h @@ -55,17 +55,6 @@ struct flt_kw_list { struct flt_kw kw[VAR_ARRAY]; }; -/* - * Filter flags set for a specific filter on channel - * - * - FILTER_FL_FORWARD_DATA : When this flag is set, the rest of the data is - * directly forwarded. For chunk-encoded HTTP - * messages, this flag is reseted between each - * chunks. - */ -#define FILTER_FL_FORWARD_DATA 0x00000001 - - /* * Callbacks available on a filter: * diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index 12d9e3330..3fee538b5 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -154,35 +154,36 @@ static int comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg) { struct comp_state *st = filter->ctx; + struct buffer *buf = msg->chn->buf; + unsigned int *nxt = &flt_rsp_nxt(filter); unsigned int len; int ret; - if (!(msg->chn->flags & CF_ISRESP) || !st->comp_algo) - return 1; - - len = MIN(msg->chunk_len + msg->next, msg->chn->buf->i) - FLT_NXT(filter, msg->chn); + len = MIN(msg->chunk_len + msg->next, buf->i) - *nxt; if (!len) return len; if (!st->initialized) { - b_adv(msg->chn->buf, FLT_FWD(filter, msg->chn) + st->sov); - ret = http_compression_buffer_init(msg->chn->buf, tmpbuf); - b_rew(msg->chn->buf, FLT_FWD(filter, msg->chn) + st->sov); + unsigned int fwd = flt_rsp_fwd(filter) + st->sov; + + b_adv(buf, fwd); + ret = http_compression_buffer_init(buf, tmpbuf); + b_rew(buf, fwd); if (ret < 0) { msg->chn->flags |= CF_WAKE_WRITE; return 0; } } - b_adv(msg->chn->buf, FLT_NXT(filter, msg->chn)); - ret = http_compression_buffer_add_data(st, msg->chn->buf, tmpbuf, len); - b_rew(msg->chn->buf, FLT_NXT(filter, msg->chn)); + b_adv(buf, *nxt); + ret = http_compression_buffer_add_data(st, buf, tmpbuf, len); + b_rew(buf, *nxt); if (ret < 0) return ret; st->initialized = 1; msg->next += ret; msg->chunk_len -= ret; - FLT_NXT(filter, msg->chn) = msg->next; + *nxt = msg->next; return 0; } @@ -541,15 +542,13 @@ http_compression_buffer_add_data(struct comp_state *st, struct buffer *in, int block1, block2; if (!sz) - return 0; + goto end; /* select the smallest size between the announced chunk size, the input * data, and the available output buffer size. The compressors are * assumed to be able to process all the bytes we pass to them at * once. */ - data_process_len = sz; - data_process_len = MIN(out->size - buffer_len(out), data_process_len); - + data_process_len = MIN(out->size - buffer_len(out), sz); block1 = data_process_len; if (block1 > bi_contig_data(in)) @@ -558,11 +557,14 @@ http_compression_buffer_add_data(struct comp_state *st, struct buffer *in, /* compressors return < 0 upon error or the amount of bytes read */ consumed_data = st->comp_algo->add_data(st->comp_ctx, bi_ptr(in), block1, out); - if (consumed_data >= 0 && block2 > 0) { - consumed_data = st->comp_algo->add_data(st->comp_ctx, in->data, block2, out); - if (consumed_data >= 0) - consumed_data += block1; - } + if (consumed_data != block1 || !block2) + goto end; + consumed_data = st->comp_algo->add_data(st->comp_ctx, in->data, block2, out); + if (consumed_data < 0) + goto end; + consumed_data += block1; + + end: return consumed_data; }