]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: http: small helpers to compute how far to rewind to find BODY and DATA
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Apr 2014 18:31:44 +0000 (20:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Apr 2014 21:15:28 +0000 (23:15 +0200)
http_body_rewind() returns the number of bytes to rewind before buf->p to
find the message's body. It relies on http_hdr_rewind() to find the beginning
and adds msg->eoh + msg->eol which are always safe.

http_data_rewind() does the same to get the beginning of the data, which
differs from above when a chunk is present. It uses the function above and
adds msg->sol.

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 aa2c901698eb053362ef797ca2d62c42e3811150..53f0eca04cec96fc88f7d113ada43a375011b0eb 100644 (file)
@@ -149,6 +149,27 @@ static inline int http_uri_rewind(const struct http_msg *msg)
        return http_hdr_rewind(msg) - msg->sl.rq.u;
 }
 
+/* Return the amount of bytes that need to be rewound before buf->p to access
+ * the current message's BODY. 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_body_rewind(const struct http_msg *msg)
+{
+       return http_hdr_rewind(msg) - msg->eoh - msg->eol;
+}
+
+/* Return the amount of bytes that need to be rewound before buf->p to access
+ * the current message's DATA. The difference with the function above is that
+ * if a chunk is present and has already been parsed, its size is skipped so
+ * that the byte pointed to is the first byte of actual data. The function is
+ * safe for use in state HTTP_MSG_DATA regardless of whether the headers were
+ * already forwarded or not.
+ */
+static inline int http_data_rewind(const struct http_msg *msg)
+{
+       return http_body_rewind(msg) - msg->sol;
+}
+
 /* 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 212e779b2cbe5c75c849ad28e43a8e52a952a170..7d0be1b701dfe9f76c3d3461f11208a79bd6ffd1 100644 (file)
@@ -299,7 +299,7 @@ struct server *get_server_ph_post(struct session *s)
        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 - http_hdr_rewind(msg)));
+       const char      *params = b_ptr(req->buf, -http_data_rewind(msg));
        const char      *p    = params;
        const char      *start, *end;