]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: add a small helper to compute the amount of body bytes present
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Apr 2014 18:08:17 +0000 (20:08 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Apr 2014 21:15:28 +0000 (23:15 +0200)
http_body_bytes() returns the number of bytes of the current message body
present in the buffer. It is compatible with being called before and after
the headers are forwarded.

This is done to centralize further ->sov changes.

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

index 1b6284b4e02ab1569fe5b0096a8bd40abf391c8c..c49cb4ef3cf23a4e7c05b01d36063d9df6eb3b59 100644 (file)
@@ -130,6 +130,22 @@ enum http_meth_t find_http_meth(const char *str, const int len);
                (msg)->eoh += (_bytes);         \
        } while (0)
 
+
+/* 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
+ * headers were already forwarded or not.
+ */
+static inline int http_body_bytes(const struct http_msg *msg)
+{
+       int len;
+
+       len = buffer_len(msg->chn->buf) - msg->sov - msg->sol;
+       if (len > msg->body_len)
+               len = msg->body_len;
+       return len;
+}
+
 /* for debugging, reports the HTTP message state name */
 static inline const char *http_msg_state_str(int msg_state)
 {
index 17e4b7fcbf75f3d0a426b3eedd27ab735bc3a79e..e40b560825980040e9a19435bb6788a54215277e 100644 (file)
@@ -298,14 +298,11 @@ struct server *get_server_ph_post(struct session *s)
        struct http_msg *msg  = &txn->req;
        struct proxy    *px   = s->be;
        unsigned int     plen = px->url_param_len;
-       unsigned long    len  = msg->body_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      *p    = params;
        const char      *start, *end;
 
-       if (len > buffer_len(req->buf) - msg->sov - msg->sol)
-               len = buffer_len(req->buf) - msg->sov - msg->sol;
-
        if (len == 0)
                return NULL;