haproxytech / haproxy-lua-http

Simple Lua HTTP helper && client for use with HAProxy.
Apache License 2.0
56 stars 23 forks source link

Unable to import json library #16

Closed Ian-Pruett closed 2 years ago

Ian-Pruett commented 2 years ago

Hi,

I saw a similar issue earlier this year about using this script to integrate authelia with haproxy 2.2. I have manually imported your lua script into /usr/local/share/lua/5.3/haproxy-lua-http.lua along with https://github.com/TimWolla/haproxy-auth-request/blob/main/auth-request.lua and I have installed lua-json library with apt as I'm running on debian buster.

After this, I tried adding the required loading lines in the global section

lua-prepend-path /usr/local/share/lua/5.3/haproxy-lua-http.lua lua-load /usr/local/share/lua/5.3/auth-request.lua When adding the second line, then HAProxy starts to complain about your file and I have no idea why:

Errors found while starting haproxy:

[NOTICE] 106/215753 (2014) : haproxy version is 2.2.22-1~bpo10+1 [NOTICE] 106/215753 (2014) : path to executable is /usr/sbin/haproxy [ALERT] 106/215753 (2014) : parsing [haproxy.cfg:5] : Lua runtime error: error loading module 'json' from file '/usr/share/lua/5.3/http.lua': /usr/share/lua/5.3/http.lua:673: too many C levels (limit is 200) in function at line 619 near 'v'

Can you help me figure this out?

Cheers! And thank you in advance for your time :)

TimWolla commented 2 years ago

Can you help me figure this out?

I suspect the issue is your lua-prepend-path line, because it will always reload the haproxy-lua-http script, as there is no ? placeholder in the path.

Ian-Pruett commented 2 years ago

Yes my global section is as follows:

global
    # Path to haproxy-lua-http
    lua-prepend-path /usr/share/lua/5.3/http.lua
    # Path to haproxy-auth-request
    lua-load /usr/share/lua/5.3/auth-request.lua

Are you saying I need to include the ? in the path??

TimWolla commented 2 years ago

Are you saying I need to include the ? in the path??

Yes and no. See this: https://www.lua.org/pil/8.1.html

Ian-Pruett commented 2 years ago

Oh wow, I've never seen that style of import before. I have zero experience with lua up until this point. Just made some changes to my haproxy.cfg and I'm able to load the file.

Thank you so much for your time!