mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
[MEDIUM] http request: simplify POST length detection
We can now rely on the pre-parsed content-length and transfer-encoding to find what the supposed body length will be.
This commit is contained in:
parent
349a0f62b5
commit
03a5633299
@ -2649,38 +2649,20 @@ int http_process_request(struct session *s, struct buffer *req, int an_bit)
|
|||||||
goto end_check_maybe_wait_for_body;
|
goto end_check_maybe_wait_for_body;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (likely(len > s->be->url_param_post_limit)) {
|
if (likely(len <= s->be->url_param_post_limit)) {
|
||||||
/* nothing to do, we got enough */
|
|
||||||
} else {
|
|
||||||
/* limit implies we are supposed to need this many bytes
|
/* limit implies we are supposed to need this many bytes
|
||||||
* to find the parameter. Let's see how many bytes we can wait for.
|
* to find the parameter. Let's see how many bytes we can
|
||||||
|
* wait for.
|
||||||
*/
|
*/
|
||||||
long long hint = len;
|
if (txn->flags & TX_REQ_TE_CHNK) {
|
||||||
struct hdr_ctx ctx;
|
|
||||||
ctx.idx = 0;
|
|
||||||
http_find_header2("Transfer-Encoding", 17, msg->sol, &txn->hdr_idx, &ctx);
|
|
||||||
if (ctx.idx && ctx.vlen >= 7 && strncasecmp(ctx.line+ctx.val, "chunked", 7) == 0) {
|
|
||||||
buffer_dont_connect(req);
|
buffer_dont_connect(req);
|
||||||
req->analysers |= AN_REQ_HTTP_BODY;
|
req->analysers |= AN_REQ_HTTP_BODY;
|
||||||
}
|
} else {
|
||||||
else {
|
long long hint = txn->req.hdr_content_len;
|
||||||
ctx.idx = 0;
|
|
||||||
http_find_header2("Content-Length", 14, msg->sol, &txn->hdr_idx, &ctx);
|
|
||||||
/* now if we have a length, we'll take the hint */
|
|
||||||
if (ctx.idx) {
|
|
||||||
/* We have Content-Length */
|
|
||||||
if (strl2llrc(ctx.line+ctx.val,ctx.vlen, &hint))
|
|
||||||
hint = 0; /* parse failure, untrusted client */
|
|
||||||
else {
|
|
||||||
if (hint > 0)
|
|
||||||
msg->hdr_content_len = hint;
|
|
||||||
else
|
|
||||||
hint = 0; /* bad client, sent negative length */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* but limited to what we care about, maybe we don't expect any entity data (hint == 0) */
|
/* but limited to what we care about, maybe we don't expect any entity data (hint == 0) */
|
||||||
if (s->be->url_param_post_limit < hint)
|
if (s->be->url_param_post_limit < hint)
|
||||||
hint = s->be->url_param_post_limit;
|
hint = s->be->url_param_post_limit;
|
||||||
|
|
||||||
/* now do we really need to buffer more data? */
|
/* now do we really need to buffer more data? */
|
||||||
if (len < hint) {
|
if (len < hint) {
|
||||||
buffer_dont_connect(req);
|
buffer_dont_connect(req);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user