Hi Thierry, guys,
When receiving a POST request on haproxy, I use lua to compute some values, and
modify the body of the request before forwarding to the backend, so my backend
can get these variables from the POST and use them.
Here is a sample cfg, and lua code to reproduce this.
##### Conf (I removed all defauts, timeout and co ..) :
frontend front-nodes
bind :80
# option to wait for the body before processing (mandatory for POST
requests)
option http-buffer-request
# default backend
default_backend be_test
http-request lua.manageRequests
##### Lua :
function manageRequests(txn)
-- create new postdata
local newPostData = core.concat()
newPostData:add('POST /test.php HTTP/1.1\r\n')
newPostData:add('Host: test1\r\n')
newPostData:add('content-type: application/x-www-form-urlencoded\r\n')
local newBodyStr = 'var1=valueA&var2=valueB'
local newBodyLen = string.len(newBodyStr)
newPostData:add('content-length: ' .. tostring(newBodyLen) .. '\r\n')
newPostData:add('\r\n')
newPostData:add(newBodyStr)
local newPostDataStr = tostring(newPostData:dump())
txn.req:send(newPostDataStr)
end
core.register_action("manageRequests", { "http-req" }, manageRequests)
This is working well in haproxy 1.8.x (x : 14 to 18) but I get the following
error with 1.9.4 (same error with 1.9.2, others 1.9.x versions not tested) :
Lua function 'manageRequests': runtime error: 0 from [C] method 'send',
/etc/haproxy/lua/bench.lua:97 C function line 80.
Line 97 of my lua file is txn.req:send(newPostDataStr)
Maybe I’m missing something on 1.9.x but cant find what, or maybe it’s a bug, I
can’t say.
Hope you can help.
Let me know if you need other informations.
Please find below the result of haproxy -vv for both versions used.
Infos on haproxy installation 1.8.14 :
HA-Proxy version 1.8.14-52e4d43 2018/09/20
Copyright 2000-2018 Willy Tarreau <[email protected]>
Build options :
TARGET = linux2628
CPU = generic
CC = gcc
CFLAGS = -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv
-fno-strict-overflow -Wno-unused-label
OPTIONS = USE_ZLIB=1 USE_REGPARM=1 USE_OPENSSL=1 USE_LUA=yes
USE_DEVICEATLAS=1 USE_SYSTEMD=1 USE_STATIC_PCRE=1 USE_PCRE_JIT=1
Default settings :
maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200
Built with OpenSSL version : OpenSSL 1.0.2o 27 Mar 2018
Running on OpenSSL version : OpenSSL 1.0.2o 27 Mar 2018
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports : SSLv3 TLSv1.0 TLSv1.1 TLSv1.2
Built with Lua version : Lua 5.3.4
Built with DeviceAtlas support.
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT
IP_FREEBIND
Encrypted password support via crypt(3): yes
Built with multi-threading support.
Built with PCRE version : 8.42 2018-03-20
Running on PCRE version : 8.42 2018-03-20
PCRE library supports JIT : yes
Built with zlib version : 1.2.7
Running on zlib version : 1.2.7
Compression algorithms supported : identity("identity"), deflate("deflate"),
raw-deflate("deflate"), gzip("gzip")
Built with network namespace support.
Available polling systems :
epoll : pref=300, test result OK
poll : pref=200, test result OK
select : pref=150, test result OK
Total: 3 (3 usable), will use epoll.
Available filters :
[SPOE] spoe
[COMP] compression
[TRACE] trace
Infos on haproxy installation 1.9.4 :
HA-Proxy version 1.9.4 2019/02/06 - https://haproxy.org/
Build options :
TARGET = linux2628
CPU = generic
CC = gcc
CFLAGS = -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv
-Wno-unused-label -Wno-sign-compare -Wno-unused-parameter
-Wno-old-style-declaration -Wno-ignored-qualifiers -Wno-clobbered
-Wno-missing-field-initializers -Wtype-limits
OPTIONS = USE_ZLIB=1 USE_REGPARM=1 USE_OPENSSL=1 USE_LUA=yes
USE_DEVICEATLAS=1 USE_SYSTEMD=1 USE_STATIC_PCRE=1 USE_PCRE_JIT=1
Default settings :
maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200
Built with OpenSSL version : OpenSSL 1.0.2o 27 Mar 2018
Running on OpenSSL version : OpenSSL 1.0.2o 27 Mar 2018
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports : SSLv3 TLSv1.0 TLSv1.1 TLSv1.2
Built with Lua version : Lua 5.3.4
Built with DeviceAtlas support.
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT
IP_FREEBIND
Built with zlib version : 1.2.7
Running on zlib version : 1.2.7
Compression algorithms supported : identity("identity"), deflate("deflate"),
raw-deflate("deflate"), gzip("gzip")
Built with PCRE version : 8.42 2018-03-20
Running on PCRE version : 8.42 2018-03-20
PCRE library supports JIT : yes
Encrypted password support via crypt(3): yes
Built with multi-threading support.
Available polling systems :
epoll : pref=300, test result OK
poll : pref=200, test result OK
select : pref=150, test result OK
Total: 3 (3 usable), will use epoll.
Available multiplexer protocols :
(protocols marked as <default> cannot be specified using 'proto' keyword)
h2 : mode=HTX side=FE|BE
h2 : mode=HTTP side=FE
<default> : mode=HTX side=FE|BE
<default> : mode=TCP|HTTP side=FE|BE
Available filters :
[SPOE] spoe
[COMP] compression
[CACHE] cache
[TRACE] trace
Best regards
Laurent