struct flt_ops comp_res_ops;
struct comp_state {
- /*
- * For both comp_ctx and comp_algo, COMP_DIR_REQ is the index
- * for requests, and COMP_DIR_RES for responses
- */
- struct comp_ctx *comp_ctx[2]; /* compression context */
- struct comp_algo *comp_algo[2]; /* compression algorithm if not NULL */
+ struct comp_ctx *comp_ctx; /* compression context */
+ struct comp_algo *comp_algo; /* compression algorithm if not NULL */
unsigned int flags; /* COMP_STATE_* */
};
if (st == NULL)
return -1;
- st->comp_algo[COMP_DIR_REQ] = NULL;
- st->comp_algo[COMP_DIR_RES] = NULL;
- st->comp_ctx[COMP_DIR_REQ] = NULL;
- st->comp_ctx[COMP_DIR_RES] = NULL;
+ st->comp_algo = NULL;
+ st->comp_ctx = NULL;
st->flags = 0;
filter->ctx = st;
return;
/* release any possible compression context */
- if (st->comp_algo[COMP_DIR_REQ])
- st->comp_algo[COMP_DIR_REQ]->end(&st->comp_ctx[COMP_DIR_REQ]);
- if (st->comp_algo[COMP_DIR_RES])
- st->comp_algo[COMP_DIR_RES]->end(&st->comp_ctx[COMP_DIR_RES]);
+ if (st->comp_algo)
+ st->comp_algo->end(&st->comp_ctx);
pool_free(pool_head_comp_state, st);
filter->ctx = NULL;
}
if (txn->meth == HTTP_METH_HEAD)
return;
if (s->be->comp && s->be->comp->algo_req != NULL)
- st->comp_algo[COMP_DIR_REQ] = s->be->comp->algo_req;
+ st->comp_algo = s->be->comp->algo_req;
else if (strm_fe(s)->comp && strm_fe(s)->comp->algo_req != NULL)
- st->comp_algo[COMP_DIR_REQ] = strm_fe(s)->comp->algo_req;
+ st->comp_algo = strm_fe(s)->comp->algo_req;
else
goto fail; /* no algo selected: nothing to do */
goto fail;
/* initialize compression */
- if (st->comp_algo[COMP_DIR_REQ]->init(&st->comp_ctx[COMP_DIR_REQ], global.tune.comp_maxlevel) < 0)
+ if (st->comp_algo->init(&st->comp_ctx, global.tune.comp_maxlevel) < 0)
goto fail;
return;
fail:
- st->comp_algo[COMP_DIR_REQ] = NULL;
+ st->comp_algo = NULL;
}
static int
if (!(msg->chn->flags & CF_ISRESP)) {
comp_prepare_compress_request(st, s, msg);
- if (st->comp_algo[COMP_DIR_REQ]) {
+ if (st->comp_algo) {
if (!set_compression_header(st, s, msg))
goto end;
register_data_filter(s, msg->chn, filter);
else {
/* Response headers have already been checked in
* comp_res_http_post_analyze callback. */
- if (st->comp_algo[COMP_DIR_RES]) {
+ if (st->comp_algo) {
if (!set_compression_header(st, s, msg))
goto end;
register_data_filter(s, msg->chn, filter);
if (to_forward != consumed)
flt_update_offsets(filter, msg->chn, to_forward - consumed);
- if (st->comp_ctx[dir] && st->comp_ctx[dir]->cur_lvl > 0) {
+ if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) {
update_freq_ctr(&global.comp_bps_in, consumed);
if (s->sess->fe_tgcounters) {
_HA_ATOMIC_ADD(&s->sess->fe_tgcounters->comp_in[dir], consumed);
{
struct comp_state *st = filter->ctx;
- if (!(msg->chn->flags & CF_ISRESP) || !st || !st->comp_algo[COMP_DIR_RES])
+ if (!(msg->chn->flags & CF_ISRESP) || !st || !st->comp_algo)
goto end;
if (strm_fe(s)->mode == PR_MODE_HTTP && s->sess->fe_tgcounters)
struct htx_sl *sl;
struct http_hdr_ctx ctx, last_vary;
struct comp_algo *comp_algo;
- int comp_index;
-
- if (msg->chn->flags & CF_ISRESP)
- comp_index = COMP_DIR_RES;
- else
- comp_index = COMP_DIR_REQ;
sl = http_get_stline(htx);
if (!sl)
goto error;
- comp_algo = st->comp_algo[comp_index];
+ comp_algo = st->comp_algo;
/* add "Transfer-Encoding: chunked" header */
if (!(msg->flags & HTTP_MSGF_TE_CHNK)) {
return 1;
error:
- st->comp_algo[comp_index]->end(&st->comp_ctx[comp_index]);
- st->comp_algo[comp_index] = NULL;
+ st->comp_algo->end(&st->comp_ctx);
+ st->comp_algo = NULL;
return 0;
}
*(ctx.value.ptr + 30) < '6' ||
(*(ctx.value.ptr + 30) == '6' &&
(ctx.value.len < 54 || memcmp(ctx.value.ptr + 51, "SV1", 3) != 0)))) {
- st->comp_algo[COMP_DIR_RES] = NULL;
+ st->comp_algo = NULL;
return 0;
}
for (comp_algo = comp_algo_back; comp_algo; comp_algo = comp_algo->next) {
if (*(ctx.value.ptr) == '*' ||
word_match(ctx.value.ptr, toklen, comp_algo->ua_name, comp_algo->ua_name_len)) {
- st->comp_algo[COMP_DIR_RES] = comp_algo;
+ st->comp_algo = comp_algo;
best_q = q;
break;
}
}
/* remove all occurrences of the header when "compression offload" is set */
- if (st->comp_algo[COMP_DIR_RES]) {
+ if (st->comp_algo) {
if ((s->be->comp && (s->be->comp->flags & COMP_FL_OFFLOAD)) ||
(strm_fe(s)->comp && (strm_fe(s)->comp->flags & COMP_FL_OFFLOAD))) {
http_remove_header(htx, &ctx);
(strm_fe(s)->comp && (comp_algo_back = strm_fe(s)->comp->algos_res))) {
for (comp_algo = comp_algo_back; comp_algo; comp_algo = comp_algo->next) {
if (comp_algo->cfg_name_len == 8 && memcmp(comp_algo->cfg_name, "identity", 8) == 0) {
- st->comp_algo[COMP_DIR_RES] = comp_algo;
+ st->comp_algo = comp_algo;
return 1;
}
}
}
- st->comp_algo[COMP_DIR_RES] = NULL;
+ st->comp_algo = NULL;
return 0;
}
unsigned int comp_minsize = 0;
/* no common compression algorithm was found in request header */
- if (st->comp_algo[COMP_DIR_RES] == NULL)
+ if (st->comp_algo == NULL)
goto fail;
/* compression already in progress */
goto fail;
/* initialize compression */
- if (st->comp_algo[COMP_DIR_RES]->init(&st->comp_ctx[COMP_DIR_RES], global.tune.comp_maxlevel) < 0)
+ if (st->comp_algo->init(&st->comp_ctx, global.tune.comp_maxlevel) < 0)
goto fail;
msg->flags |= HTTP_MSGF_COMPRESSING;
return 1;
fail:
- st->comp_algo[COMP_DIR_RES] = NULL;
+ st->comp_algo = NULL;
return 0;
}
struct buffer *out, int dir)
{
- return st->comp_algo[dir]->add_data(st->comp_ctx[dir], data, len, out);
+ return st->comp_algo->add_data(st->comp_ctx, data, len, out);
}
static int
{
if (end)
- return st->comp_algo[dir]->finish(st->comp_ctx[dir], out);
+ return st->comp_algo->finish(st->comp_ctx, out);
else
- return st->comp_algo[dir]->flush(st->comp_ctx[dir], out);
+ return st->comp_algo->flush(st->comp_ctx, out);
}
smp->data.type = SMP_T_STR;
smp->flags = SMP_F_CONST;
- smp->data.u.str.area = st->comp_algo[COMP_DIR_RES]->cfg_name;
- smp->data.u.str.data = st->comp_algo[COMP_DIR_RES]->cfg_name_len;
+ smp->data.u.str.area = st->comp_algo->cfg_name;
+ smp->data.u.str.data = st->comp_algo->cfg_name_len;
return 1;
}
return 0;