mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
[MINOR] code factoring : capture_headers() serves requests and responses
Both request and response captures will have to parse headers following the same methods. It's better to factorize the code, hence the new capture_headers() function.
This commit is contained in:
parent
4b89ad4358
commit
117f59e282
100
src/proto_http.c
100
src/proto_http.c
@ -516,6 +516,59 @@ int process_session(struct task *t)
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Capture headers from message starting at <som> according to header list
|
||||||
|
* <cap_hdr>, and fill the <idx> 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 <ptr> and <end>, starting with
|
* This function parses a response line between <ptr> and <end>, starting with
|
||||||
* parser state <state>. Only states HTTP_MSG_RPVER, HTTP_MSG_RPVER_SP,
|
* parser state <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 */
|
/* 5: we may need to capture headers */
|
||||||
if (unlikely((t->logs.logwait & LW_REQHDR) && t->fe->fiprm->req_cap)) {
|
if (unlikely((t->logs.logwait & LW_REQHDR) && t->fe->fiprm->req_cap))
|
||||||
char *eol, *sol, *col, *sov;
|
capture_headers(req->data + msg->som, &txn->hdr_idx,
|
||||||
int cur_idx;
|
txn->req.cap, t->fe->fiprm->req_cap);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 6: we will have to evaluate the filters.
|
* 6: we will have to evaluate the filters.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user