]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: add a small helper to compute how far to rewind to find URI
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Apr 2014 18:24:24 +0000 (20:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Apr 2014 21:15:28 +0000 (23:15 +0200)
http_uri_rewind() returns the number of bytes to rewind before buf->p to
find the URI. It relies on http_hdr_rewind() to find the beginning and
is just here to simplify operations.

The purpose is to centralize further ->sov changes aiming at avoiding
to rely on buf->o.

include/proto/proto_http.h
src/backend.c

index 6566c0a565b48baffbd75401d670ef8bf79d2f5f..aa2c901698eb053362ef797ca2d62c42e3811150 100644 (file)
@@ -140,6 +140,15 @@ static inline int http_hdr_rewind(const struct http_msg *msg)
        return msg->chn->buf->o;
 }
 
+/* Return the amount of bytes that need to be rewound before buf->p to access
+ * the current message's URI. The purpose is to be able to easily fetch
+ * the message's beginning before headers are forwarded, as well as after.
+ */
+static inline int http_uri_rewind(const struct http_msg *msg)
+{
+       return http_hdr_rewind(msg) - msg->sl.rq.u;
+}
+
 /* Return the maximum amount of bytes that may be read after the beginning of
  * the message body, according to the advertised length. The function is safe
  * for use between HTTP_MSG_BODY and HTTP_MSG_DATA regardless of whether the
index 5a011b15134ee88ad82526c69c7aa3ea8ee8c387..212e779b2cbe5c75c849ad28e43a8e52a952a170 100644 (file)
@@ -615,7 +615,7 @@ int assign_server(struct session *s)
                                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 - http_hdr_rewind(&s->txn.req))),
+                                                   b_ptr(s->req->buf, -http_uri_rewind(&s->txn.req)),
                                                    s->txn.req.sl.rq.u_l);
                                break;
 
@@ -625,7 +625,7 @@ int assign_server(struct session *s)
                                        break;
 
                                srv = get_server_ph(s->be,
-                                                   b_ptr(s->req->buf, (int)(s->txn.req.sl.rq.u - http_hdr_rewind(&s->txn.req))),
+                                                   b_ptr(s->req->buf, -http_uri_rewind(&s->txn.req)),
                                                    s->txn.req.sl.rq.u_l);
 
                                if (!srv && s->txn.meth == HTTP_METH_POST)