]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: lua: sockets receive behavior doesn't follows the specs
authorThierry FOURNIER <tfournier@exceliance.fr>
Mon, 9 Mar 2015 17:35:06 +0000 (18:35 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Mar 2015 17:46:48 +0000 (18:46 +0100)
Specs says that the receive() function with an argument "*l"
must return a line without the final "\n" ( or without "\r\n").
This patch removes these two final bytes.

src/hlua.c

index 260646bc9476f1e26918cff4fe14792b1cfa4026..564f5bace07077508aed415f00fc4a290bf9df28 100644 (file)
@@ -1169,6 +1169,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
        int len1;
        char *blk2;
        int len2;
+       int skip_at_end = 0;
 
        /* Check if this lua stack is schedulable. */
        if (!hlua || !hlua->task)
@@ -1187,6 +1188,28 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
                        goto connection_closed;
                if (nblk == 0) /* No data avalaible. */
                        goto connection_empty;
+
+               /* remove final \r\n. */
+               if (nblk == 1) {
+                       if (blk1[len1-1] == '\n') {
+                               len1--;
+                               skip_at_end++;
+                               if (blk1[len1-1] == '\r') {
+                                       len1--;
+                                       skip_at_end++;
+                               }
+                       }
+               }
+               else {
+                       if (blk2[len2-1] == '\n') {
+                               len2--;
+                               skip_at_end++;
+                               if (blk2[len2-1] == '\r') {
+                                       len2--;
+                                       skip_at_end++;
+                               }
+                       }
+               }
        }
 
        else if (wanted == HLSR_READ_ALL) {
@@ -1224,7 +1247,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
        }
 
        /* Consume data. */
-       bo_skip(socket->s->si[0].ob, len);
+       bo_skip(socket->s->si[0].ob, len + skip_at_end);
 
        /* Don't wait anything. */
        si_update(&socket->s->si[0]);