1
0
mirror of https://github.com/graygnuorg/pound.git synced 2026-10-23 22:28:53 +03:00
Files
pound/tests/lua-load.at
Sergey Poznyakoff 0e5d6f999c Lua support
Lua functions can be used as checks in Service section (LuaMatch
statement) as well as to implement new backends (LuaBackend
statement).  Lua is configured and its sources are loaded in the
new Lua section statement.

This commit also fixes a minor bug in SendFile implementation.

* .github/workflows/testsuite.yml: Test Lua
* NEWS: Version 4.18.90
* configure.ac: Test for Lua. New option: --with-lua.
* src/pndlua.c: New file.
* src/Makefile.am [COND_LUA] (pound_SOURCES): Add pndlua.c
* src/pound.h (http_header_list_append): Mark text as const.
(http_header_list_remove_field)
(http_request_count_query_param): New proto.
(PNDLUA_CTX_GLOBAL, PNDLUA_CTX_THREAD)
(BE_LUA, COND_LUA): New constants.
(pndlua_closure): New struct.
(struct _backend): New member v.lua.
(_service_cond): New member: clua.
(pndlua_init, pndlua_match, pndlua_backend)
(pndlua_parse_config, pndlua_parse_closure): New protos.
* src/config.c: New section: Lua.
New statements: Lua.Path, Lua.CPath, Lua.Load, Lua.LoadGlobal,
LuaMatch, LuaBackend.
(parse_config_file): Call pndlua_init.
(pound_settings): Reflect Lua support.
* src/extern.h (parser_loop): New function.
* src/http.c (file_response): Don't use request.path, call
http_request_get_path instead.  This ensures the request has been
properly parsed.
(http_header_alloc, http_header_list_append): Mark text argument as
static.
(http_header_list_remove_field): New function.
(http_request_count_query_param): New function.
(match_cond): Handle COND_LUA conditionals.
(http_process_request): Handle BE_LUA (Lua backends).
* src/pound-mode.el: Support for Lua keywords.
* src/svc.c (str_be, backend_serialize): Handle BE_LUA.

* src/cfgparser.c (input_gettkn): Improve escape sequence
handling.

* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
* tests/atlocal.in (LUA_AVAILABLE): New variable.
* tests/lua-be.at: New file.
* tests/lua-http.at: New file.
* tests/lua-load.at: New file.
* tests/lua-match.at: New file.
* tests/lua-path.at: New file.
* tests/sendfile.at: Test SendFile with unmodified path as well.
2025-11-02 13:46:38 +02:00

80 lines
1.5 KiB
Plaintext

# This file is part of pound testsuite. -*- autotest -*-
# Copyright (C) 2025 Sergey Poznyakoff
#
# Pound is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Pound is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pound. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([Lua load])
AT_KEYWORDS([cond lua lua-load])
AT_SKIP_IF([test "$LUA_AVAILABLE" != 1])
AT_DATA([gtest.lua],
[function gtest()
return pound.loadctx == nil
end
pound.log(pound.DEBUG, "Global Context " .. tostring(pound.loadctx))
])
AT_DATA([xtest.lua],
[function xtest()
return pound.loadctx == nil
end
pound.log(pound.DEBUG, "Context " .. tostring(pound.loadctx))
])
PT_CHECK([
WorkerMinCount 2
WorkerMaxCount 2
Lua
Load "xtest.lua"
LoadGlobal "gtest.lua"
End
ListenHTTP
Service
Path "/echo/foo"
LuaMatch "xtest"
Backend
End
End
Service
Path "/echo/bar"
LuaMatch "gtest"
Backend
End
End
End
],
[GET /echo/foo
end
200
x-backend-number: 0
end
GET /echo/bar
end
200
x-backend-number: 1
end
])
AT_CHECK([grep Context pound.log],
[0],
[pound: Global Context 0
pound: Context 1
pound: Context 2
])
AT_CLEANUP