MEDIUM: http: add a small helper to compute how far to rewind to find headers
http_hdr_rewind() returns the number of bytes to rewind before buf->p to
find the beginning of headers. At the moment it's not exact as it still
relies on buf->o, assuming that no other data from a past message were
pending there, but it's what was done till there.
The purpose is to centralize further ->sov changes aiming at avoiding
to rely on buf->o.
diff --git a/src/backend.c b/src/backend.c
index e40b560..5a011b1 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -299,7 +299,7 @@
struct proxy *px = s->be;
unsigned int plen = px->url_param_len;
unsigned long len = http_body_bytes(msg);
- const char *params = b_ptr(req->buf, (int)(msg->sov + msg->sol - req->buf->o));
+ const char *params = b_ptr(req->buf, (int)(msg->sov + msg->sol - http_hdr_rewind(msg)));
const char *p = params;
const char *start, *end;
@@ -386,7 +386,7 @@
ctx.idx = 0;
/* if the message is chunked, we skip the chunk size, but use the value as len */
- http_find_header2(px->hh_name, plen, b_ptr(s->req->buf, (int)-s->req->buf->o), &txn->hdr_idx, &ctx);
+ http_find_header2(px->hh_name, plen, b_ptr(s->req->buf, -http_hdr_rewind(&txn->req)), &txn->hdr_idx, &ctx);
/* if the header is not found or empty, let's fallback to round robin */
if (!ctx.idx || !ctx.vlen)
@@ -615,7 +615,7 @@
if (s->txn.req.msg_state < HTTP_MSG_BODY)
break;
srv = get_server_uh(s->be,
- b_ptr(s->req->buf, (int)(s->txn.req.sl.rq.u - s->req->buf->o)),
+ b_ptr(s->req->buf, (int)(s->txn.req.sl.rq.u - http_hdr_rewind(&s->txn.req))),
s->txn.req.sl.rq.u_l);
break;
@@ -625,7 +625,7 @@
break;
srv = get_server_ph(s->be,
- b_ptr(s->req->buf, (int)(s->txn.req.sl.rq.u - s->req->buf->o)),
+ b_ptr(s->req->buf, (int)(s->txn.req.sl.rq.u - http_hdr_rewind(&s->txn.req))),
s->txn.req.sl.rq.u_l);
if (!srv && s->txn.meth == HTTP_METH_POST)
@@ -967,7 +967,7 @@
((struct sockaddr_in *)&srv_conn->addr.from)->sin_port = 0;
((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr = 0;
- b_rew(s->req->buf, rewind = s->req->buf->o);
+ b_rew(s->req->buf, rewind = http_hdr_rewind(&s->txn.req));
if (http_get_hdr(&s->txn.req, src->bind_hdr_name, src->bind_hdr_len,
&s->txn.hdr_idx, src->bind_hdr_occ, NULL, &vptr, &vlen)) {
((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr =