HAProxy community

Haproxy1.6 modify response body by Lua problem


#1

Ubuntu 14 Server with Hparoxy 1.6
My problem is when response’s body size just 505 then browser return ERR_EMPTY_RESPONSE
but when response’s body size big then 2877 return OK.

[WARNING] 157/093512 (14599) : config : log format ignored for frontend ‘http_80_in’ since it has no log address.
[info] 157/093516 (14599) : start debug …
[info] 157/093516 (14599) : in: 505
[info] 157/093516 (14599) : out: 0
[info] 157/093516 (14599) : before send
[info] 157/093516 (14599) : out: 0
[info] 157/093516 (14599) : in: 0
[info] 157/093516 (14599) : end debug …
[info] 157/093520 (14599) : start debug …
[info] 157/093520 (14599) : in: 2877
[info] 157/093520 (14599) : out: 0
[info] 157/093520 (14599) : before send
[info] 157/093520 (14599) : out: 0
[info] 157/093520 (14599) : in: 2877
[info] 157/093520 (14599) : end debug …

lua scripts
core.register_action(“file-get-oa”, { “http-res” }, function(txn)
txn:Info(‘start debug …’)
txn:Info('in: '… txn.res:get_in_len())
txn:Info('out: '… txn.res:get_out_len())

   local json = txn.res:get()
   txn:Info( ' before send')
   txn.res:set(json)
   txn:Info(' out: '.. txn.res:get_out_len())
   txn:Info(' in: '.. txn.res:get_in_len())
   txn:Info('end debug .........')
end)

haproxy.cfg
backend oafile-server
mode http
option http-server-close
http-request replace-header Host ^gys.zxlm.cn$ oa.zxlm.cn

acl htmltxt res.hdr(Content-Type) -m beg text application/json
acl gys var(txn.requesthost) -m str gys.zxlm.cn
http-response lua.file-get-oa if !gys htmltxt
http-response lua.file-get-gys if gys htmltxt

server oa_File_8060 10.219.8.101:8060 check


#2

Moved to help section, as you are asking for Help, rather than providing a working LUA script for others.


#3

Is possible config txn channel cache buffer size.