MINOR: http: add a small helper to compute the amount of body bytes present

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.
This commit is contained in:
Willy Tarreau 2014-04-17 20:08:17 +02:00
parent c24715e5f7
commit 2d8e485a7c
2 changed files with 17 additions and 4 deletions

View 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)
{

View 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;