From 362b34d05ccce00e93447fa0764231768ffb0453 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 21 Jan 2007 20:49:31 +0100 Subject: [PATCH] [MINOR] move the response headers to the http_req --- include/types/session.h | 3 +-- src/client.c | 18 +++++++++--------- src/log.c | 4 ++-- src/proto_http.c | 13 +++++++++---- src/session.c | 8 ++++---- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/include/types/session.h b/include/types/session.h index 1edc2f854..bbb0ebe07 100644 --- a/include/types/session.h +++ b/include/types/session.h @@ -139,7 +139,7 @@ struct http_msg { int sor; /* Start Of Request, relative to buffer */ int col, sov; /* current header: colon, start of value */ int eoh; /* End Of Headers, relative to buffer */ - char **cap; /* array of captured request headers (may be NULL) */ + char **cap; /* array of captured headers (may be NULL) */ union { /* useful start line pointers, relative to buffer */ struct { int l; /* request line length (not including CR) */ @@ -187,7 +187,6 @@ struct session { struct sockaddr_in srv_addr; /* the address to connect to */ struct server *srv; /* the server being used */ struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */ - char **rsp_cap; /* array of captured response headers (may be NULL) */ struct http_req hreq; /* current HTTP request being processed. Should become a list. */ struct { int logwait; /* log fields waiting to be collected : LW_* */ diff --git a/src/client.c b/src/client.c index 8bcd1431b..e4babba08 100644 --- a/src/client.c +++ b/src/client.c @@ -198,9 +198,9 @@ int event_accept(int fd) { s->uniq_id = totalconn; p->cum_feconn++; /* cum_beconn will be increased once assigned */ - s->rsp_cap = NULL; hreq = &s->hreq; hreq->req.cap = NULL; + hreq->rsp.cap = NULL; hreq->hdr_idx.v = NULL; hreq->hdr_idx.size = hreq->hdr_idx.used = 0; @@ -226,7 +226,7 @@ int event_accept(int fd) { if (p->fiprm->nb_rsp_cap > 0) { - if ((s->rsp_cap = + if ((hreq->rsp.cap = pool_alloc_from(p->fiprm->rsp_cap_pool, p->fiprm->nb_rsp_cap*sizeof(char *))) == NULL) { /* no memory */ if (hreq->req.cap != NULL) @@ -236,15 +236,15 @@ int event_accept(int fd) { pool_free(session, s); return 0; } - memset(s->rsp_cap, 0, p->fiprm->nb_rsp_cap*sizeof(char *)); + memset(hreq->rsp.cap, 0, p->fiprm->nb_rsp_cap*sizeof(char *)); } if ((hreq->hdr_idx.v = pool_alloc_from(p->hdr_idx_pool, hreq->hdr_idx.size*sizeof(*hreq->hdr_idx.v))) == NULL) { /* no memory */ - if (s->rsp_cap != NULL) - pool_free_to(p->fiprm->rsp_cap_pool, s->rsp_cap); + if (hreq->rsp.cap != NULL) + pool_free_to(p->fiprm->rsp_cap_pool, hreq->rsp.cap); if (hreq->req.cap != NULL) pool_free_to(p->fiprm->req_cap_pool, hreq->req.cap); close(cfd); /* nothing can be done for this fd without memory */ @@ -333,8 +333,8 @@ int event_accept(int fd) { if ((s->req = pool_alloc(buffer)) == NULL) { /* no memory */ if (hreq->hdr_idx.v != NULL) pool_free_to(p->hdr_idx_pool, hreq->hdr_idx.v); - if (s->rsp_cap != NULL) - pool_free_to(p->fiprm->rsp_cap_pool, s->rsp_cap); + if (hreq->rsp.cap != NULL) + pool_free_to(p->fiprm->rsp_cap_pool, hreq->rsp.cap); if (hreq->req.cap != NULL) pool_free_to(p->fiprm->req_cap_pool, hreq->req.cap); close(cfd); /* nothing can be done for this fd without memory */ @@ -356,8 +356,8 @@ int event_accept(int fd) { pool_free(buffer, s->req); if (hreq->hdr_idx.v != NULL) pool_free_to(p->hdr_idx_pool, hreq->hdr_idx.v); - if (s->rsp_cap != NULL) - pool_free_to(p->fiprm->rsp_cap_pool, s->rsp_cap); + if (hreq->rsp.cap != NULL) + pool_free_to(p->fiprm->rsp_cap_pool, hreq->rsp.cap); if (hreq->req.cap != NULL) pool_free_to(p->fiprm->req_cap_pool, hreq->req.cap); close(cfd); /* nothing can be done for this fd without memory */ diff --git a/src/log.c b/src/log.c index e25536fc0..805281621 100644 --- a/src/log.c +++ b/src/log.c @@ -368,9 +368,9 @@ void sess_log(struct session *s) for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) { if (hdr) *(h++) = '|'; - if (s->rsp_cap[hdr] != NULL) + if (hreq->rsp.cap[hdr] != NULL) h = encode_string(h, tmpline + sizeof(tmpline) - 4, - '#', hdr_encode_map, s->rsp_cap[hdr]); + '#', hdr_encode_map, hreq->rsp.cap[hdr]); } *(h++) = '}'; } diff --git a/src/proto_http.c b/src/proto_http.c index 92e818c02..83af0c7e4 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -2192,16 +2192,21 @@ int process_srv(struct session *t) if ((h->namelen + 2 <= ptr - rep->h) && (rep->h[h->namelen] == ':') && (strncasecmp(rep->h, h->name, h->namelen) == 0)) { + if (hreq->rsp.cap[h->index] == NULL) + hreq->rsp.cap[h->index] = + pool_alloc_from(h->pool, h->len + 1); - if (t->rsp_cap[h->index] == NULL) - t->rsp_cap[h->index] = pool_alloc_from(h->pool, h->len + 1); + if (hreq->rsp.cap[h->index] == NULL) { + Alert("HTTP capture : out of memory.\n"); + continue; + } len = ptr - (rep->h + h->namelen + 2); if (len > h->len) len = h->len; - memcpy(t->rsp_cap[h->index], rep->h + h->namelen + 2, len); - t->rsp_cap[h->index][len]=0; + memcpy(hreq->rsp.cap[h->index], rep->h + h->namelen + 2, len); + hreq->rsp.cap[h->index][len]=0; } } diff --git a/src/session.c b/src/session.c index 3e1cc6161..1bf0f27df 100644 --- a/src/session.c +++ b/src/session.c @@ -45,13 +45,13 @@ void session_free(struct session *s) if (hreq->hdr_idx.v != NULL) pool_free_to(s->fe->hdr_idx_pool, hreq->hdr_idx.v); - if (s->rsp_cap != NULL) { + if (hreq->rsp.cap != NULL) { struct cap_hdr *h; for (h = s->fe->fiprm->rsp_cap; h; h = h->next) { - if (s->rsp_cap[h->index] != NULL) - pool_free_to(h->pool, s->rsp_cap[h->index]); + if (hreq->rsp.cap[h->index] != NULL) + pool_free_to(h->pool, hreq->rsp.cap[h->index]); } - pool_free_to(s->fe->fiprm->rsp_cap_pool, s->rsp_cap); + pool_free_to(s->fe->fiprm->rsp_cap_pool, hreq->rsp.cap); } if (hreq->req.cap != NULL) { struct cap_hdr *h;