]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] backend: remove HTTP POST parsing from get_server_ph_post()
authorWilly Tarreau <w@1wt.eu>
Sun, 6 Dec 2009 18:18:09 +0000 (19:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Dec 2009 08:52:42 +0000 (09:52 +0100)
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.

src/backend.c

index 70201ce2c95710ab2f5e720dfd57a69c455639a4..6a2670a67f32499e1f105a24fd982324c3a83e0f 100644 (file)
@@ -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.