From: Willy Tarreau Date: Sun, 6 Dec 2009 18:18:09 +0000 (+0100) Subject: [MEDIUM] backend: remove HTTP POST parsing from get_server_ph_post() X-Git-Tag: v1.4-dev5~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=157dd638e98e754a4d279d3ed1206eff37e0346a;p=thirdparty%2Fhaproxy.git [MEDIUM] backend: remove HTTP POST parsing from get_server_ph_post() Now that the HTTP analyser will already have parsed the beginning of the request body, we don't have to check for transfer-encoding anymore since we have the current chunk size in hdr_content_len. --- diff --git a/src/backend.c b/src/backend.c index 70201ce2c9..6a2670a67f 100644 --- a/src/backend.c +++ b/src/backend.c @@ -244,55 +244,18 @@ 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 body; - unsigned long len; - const char *params; - struct hdr_ctx ctx; - const char *p; - - /* tot_weight appears to mean srv_count */ - if (px->lbprm.tot_weight == 0) - return NULL; + unsigned long len = msg->hdr_content_len; + const char *params = req->data + msg->sov; + const char *p = params; - body = msg->sol[msg->eoh] == '\r' ? msg->eoh + 2 : msg->eoh + 1; - len = req->l - body; - params = req->data + body; + if (len > req->l - msg->sov) + len = req->l - msg->sov; - if ( len == 0 ) + if (len == 0) return NULL; - ctx.idx = 0; - - /* if the message is chunked, we skip the chunk size, but use the value as len */ - 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) { - unsigned int chunk = 0; - while ( params < (req->data+req->max_len) && !HTTP_IS_CRLF(*params)) { - char c = *params; - if (ishex(c)) { - unsigned int hex = toupper(c) - '0'; - if ( hex > 9 ) - hex -= 'A' - '9' - 1; - chunk = (chunk << 4) | hex; - } - else - return NULL; - params++; - len--; - } - /* spec says we get CRLF */ - if (HTTP_IS_CRLF(*params) && HTTP_IS_CRLF(params[1])) - params += 2; - else - return NULL; - /* ok we have some encoded length, just inspect the first chunk */ - len = chunk; - } - - if (len > req->l - body) - len = req->l - body; - - p = params; + if (px->lbprm.tot_weight == 0) + return NULL; while (len > plen) { /* Look for the parameter name followed by an equal symbol */ @@ -307,9 +270,9 @@ struct server *get_server_ph_post(struct session *s) while (len && *p != '&') { if (unlikely(!HTTP_IS_TOKEN(*p))) { - /* if in a POST, body must be URI encoded or its not a URI. - * Do not interprete any possible binary data as a parameter. - */ + /* if in a POST, body must be URI encoded or it's not a URI. + * Do not interprete any possible binary data as a parameter. + */ if (likely(HTTP_IS_LWS(*p))) /* eol, uncertain uri len */ break; return NULL; /* oh, no; this is not uri-encoded.