diff --git a/src/proto_http.c b/src/proto_http.c index 0eea5fdfb..f967c526d 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -516,6 +516,59 @@ int process_session(struct task *t) } \ } while (0) + +/* + * Capture headers from message starting at according to header list + * , and fill the structure appropriately. + */ +void capture_headers(char *som, struct hdr_idx *idx, + char **cap, struct cap_hdr *cap_hdr) +{ + char *eol, *sol, *col, *sov; + int cur_idx; + struct cap_hdr *h; + int len; + + sol = som + hdr_idx_first_pos(idx); + cur_idx = hdr_idx_first_idx(idx); + + while (cur_idx) { + eol = sol + idx->v[cur_idx].len; + + col = sol; + while (col < eol && *col != ':') + col++; + + sov = col + 1; + while (sov < eol && http_is_lws[(unsigned char)*sov]) + sov++; + + for (h = cap_hdr; h; h = h->next) { + if ((h->namelen == col - sol) && + (strncasecmp(sol, h->name, h->namelen) == 0)) { + if (cap[h->index] == NULL) + cap[h->index] = + pool_alloc_from(h->pool, h->len + 1); + + if (cap[h->index] == NULL) { + Alert("HTTP capture : out of memory.\n"); + continue; + } + + len = eol - sov; + if (len > h->len) + len = h->len; + + memcpy(cap[h->index], sov, len); + cap[h->index][len]=0; + } + } + sol = eol + idx->v[cur_idx].cr + 1; + cur_idx = idx->v[cur_idx].next; + } +} + + /* * This function parses a response line between and , starting with * parser state . Only states HTTP_MSG_RPVER, HTTP_MSG_RPVER_SP, @@ -1346,50 +1399,9 @@ int process_cli(struct session *t) /* 5: we may need to capture headers */ - if (unlikely((t->logs.logwait & LW_REQHDR) && t->fe->fiprm->req_cap)) { - char *eol, *sol, *col, *sov; - int cur_idx; - struct cap_hdr *h; - int len; - - sol = req->data + msg->som + hdr_idx_first_pos(&txn->hdr_idx); - cur_idx = hdr_idx_first_idx(&txn->hdr_idx); - - while (cur_idx) { - eol = sol + txn->hdr_idx.v[cur_idx].len; - - col = sol; - while (col < eol && *col != ':') - col++; - - sov = col + 1; - while (sov < eol && http_is_lws[(unsigned char)*sov]) - sov++; - - for (h = t->fe->fiprm->req_cap; h; h = h->next) { - if ((h->namelen == col - sol) && - (strncasecmp(sol, h->name, h->namelen) == 0)) { - if (txn->req.cap[h->index] == NULL) - txn->req.cap[h->index] = - pool_alloc_from(h->pool, h->len + 1); - - if (txn->req.cap[h->index] == NULL) { - Alert("HTTP capture : out of memory.\n"); - continue; - } - - len = eol - sov; - if (len > h->len) - len = h->len; - - memcpy(txn->req.cap[h->index], sov, len); - txn->req.cap[h->index][len]=0; - } - } - sol = eol + txn->hdr_idx.v[cur_idx].cr + 1; - cur_idx = txn->hdr_idx.v[cur_idx].next; - } - } + if (unlikely((t->logs.logwait & LW_REQHDR) && t->fe->fiprm->req_cap)) + capture_headers(req->data + msg->som, &txn->hdr_idx, + txn->req.cap, t->fe->fiprm->req_cap); /* * 6: we will have to evaluate the filters.