struct stream *s,
struct http_msg *msg);
-static int http_compression_buffer_init(struct buffer *in, struct buffer *out);
+static int http_compression_buffer_init(struct channel *inc, struct buffer *out);
static int http_compression_buffer_add_data(struct comp_state *st,
struct buffer *in,
struct buffer *out, int sz);
{
struct comp_state *st = filter->ctx;
struct channel *chn = msg->chn;
- struct buffer *buf = chn->buf;
unsigned int *nxt = &flt_rsp_nxt(filter);
unsigned int len;
int ret;
- len = MIN(msg->chunk_len + msg->next, buf->i) - *nxt;
+ len = MIN(msg->chunk_len + msg->next, ci_data(chn)) - *nxt;
if (!len)
return len;
b_reset(tmpbuf);
c_adv(chn, fwd);
- ret = http_compression_buffer_init(buf, zbuf);
+ ret = http_compression_buffer_init(chn, zbuf);
c_rew(chn, fwd);
if (ret < 0) {
msg->chn->flags |= CF_WAKE_WRITE;
block = ci_contig_data(chn);
memcpy(b_tail(tmpbuf), ci_head(chn), block);
if (len > block)
- memcpy(b_tail(tmpbuf)+block, buf->data, len-block);
+ memcpy(b_tail(tmpbuf)+block, b_orig(chn->buf), len-block);
c_rew(chn, *nxt);
b_add(tmpbuf, len);
}
else {
c_adv(chn, *nxt);
- ret = http_compression_buffer_add_data(st, buf, zbuf, len);
+ ret = http_compression_buffer_add_data(st, chn->buf, zbuf, len);
c_rew(chn, *nxt);
if (ret < 0)
return ret;
b_reset(tmpbuf);
c_adv(chn, fwd);
- http_compression_buffer_init(chn->buf, zbuf);
+ http_compression_buffer_init(chn, zbuf);
c_rew(chn, fwd);
st->initialized = 1;
}
struct http_msg *msg)
{
struct http_txn *txn = s->txn;
- struct buffer *req = msg->chn->buf;
+ struct channel *req = msg->chn;
struct hdr_ctx ctx;
struct comp_algo *comp_algo = NULL;
struct comp_algo *comp_algo_back = NULL;
* See http://zoompf.com/2012/02/lose-the-wait-http-compression for more details.
*/
ctx.idx = 0;
- if (http_find_header2("User-Agent", 10, req->p, &txn->hdr_idx, &ctx) &&
+ if (http_find_header2("User-Agent", 10, ci_head(req), &txn->hdr_idx, &ctx) &&
ctx.vlen >= 9 &&
memcmp(ctx.line + ctx.val, "Mozilla/4", 9) == 0 &&
(ctx.vlen < 31 ||
int best_q = 0;
ctx.idx = 0;
- while (http_find_header2("Accept-Encoding", 15, req->p, &txn->hdr_idx, &ctx)) {
+ while (http_find_header2("Accept-Encoding", 15, ci_head(req), &txn->hdr_idx, &ctx)) {
const char *qval;
int q;
int toklen;
(strm_fe(s)->comp && strm_fe(s)->comp->offload)) {
http_remove_header2(msg, &txn->hdr_idx, &ctx);
ctx.idx = 0;
- while (http_find_header2("Accept-Encoding", 15, req->p, &txn->hdr_idx, &ctx)) {
+ while (http_find_header2("Accept-Encoding", 15, ci_head(req), &txn->hdr_idx, &ctx)) {
http_remove_header2(msg, &txn->hdr_idx, &ctx);
}
}
select_compression_response_header(struct comp_state *st, struct stream *s, struct http_msg *msg)
{
struct http_txn *txn = s->txn;
- struct buffer *res = msg->chn->buf;
+ struct channel *c = msg->chn;
struct hdr_ctx ctx;
struct comp_type *comp_type;
/* content is already compressed */
ctx.idx = 0;
- if (http_find_header2("Content-Encoding", 16, res->p, &txn->hdr_idx, &ctx))
+ if (http_find_header2("Content-Encoding", 16, ci_head(c), &txn->hdr_idx, &ctx))
goto fail;
/* no compression when Cache-Control: no-transform is present in the message */
ctx.idx = 0;
- while (http_find_header2("Cache-Control", 13, res->p, &txn->hdr_idx, &ctx)) {
+ while (http_find_header2("Cache-Control", 13, ci_head(c), &txn->hdr_idx, &ctx)) {
if (word_match(ctx.line + ctx.val, ctx.vlen, "no-transform", 12))
goto fail;
}
* the priority.
*/
ctx.idx = 0;
- if (http_find_header2("Content-Type", 12, res->p, &txn->hdr_idx, &ctx)) {
+ if (http_find_header2("Content-Type", 12, ci_head(c), &txn->hdr_idx, &ctx)) {
if (ctx.vlen >= 9 && strncasecmp("multipart", ctx.line+ctx.val, 9) == 0)
goto fail;
/* remove Content-Length header */
ctx.idx = 0;
- if ((msg->flags & HTTP_MSGF_CNT_LEN) && http_find_header2("Content-Length", 14, res->p, &txn->hdr_idx, &ctx))
+ if ((msg->flags & HTTP_MSGF_CNT_LEN) && http_find_header2("Content-Length", 14, ci_head(c), &txn->hdr_idx, &ctx))
http_remove_header2(msg, &txn->hdr_idx, &ctx);
/* add Transfer-Encoding header */
* Init HTTP compression
*/
static int
-http_compression_buffer_init(struct buffer *in, struct buffer *out)
+http_compression_buffer_init(struct channel *inc, struct buffer *out)
{
/* output stream requires at least 10 bytes for the gzip header, plus
* at least 8 bytes for the gzip trailer (crc+len), plus a possible
* plus at most 5 bytes per 32kB block and 2 bytes to close the stream.
*/
- if (b_room(in) < 20 + 5 * ((in->i + 32767) >> 15))
+ if (c_room(inc) < 20 + 5 * ((ci_data(inc) + 32767) >> 15))
return -1;
/* prepare an empty output buffer in which we reserve enough room for
* cancel the operation later, it's cheap.
*/
b_reset(out);
- out->o = in->o;
+ out->o = co_data(inc);
out->p += out->o;
out->i = 10;
return 0;
return -1; /* flush failed */
#endif /* USE_ZLIB */
- if (ob->i == 10) {
+ if (b_data(ob) == 0) {
/* No data were appended, let's drop the output buffer and
* keep the input buffer unchanged.
*/