Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haproxytech/haproxy-lua-http
Simple Lua HTTP helper && client for use with HAProxy.
https://github.com/haproxytech/haproxy-lua-http
haproxy http-client lua
Last synced: 3 months ago
JSON representation
Simple Lua HTTP helper && client for use with HAProxy.
- Host: GitHub
- URL: https://github.com/haproxytech/haproxy-lua-http
- Owner: haproxytech
- License: apache-2.0
- Created: 2018-05-07T11:00:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-05T17:39:20.000Z (over 3 years ago)
- Last Synced: 2024-08-02T15:54:26.043Z (6 months ago)
- Topics: haproxy, http-client, lua
- Language: Lua
- Homepage:
- Size: 71.3 KB
- Stars: 55
- Watchers: 14
- Forks: 24
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Lua HTTP client library for HAProxy
===================================This is a pure Lua HTTP 1.1 library for HAProxy. It should work on any modern
HAProxy version (1.7+)The library is loosely modeled after Python's Requests Library using the same
attribute names and similar calling conventions for "HTTP verb" methods (where
we use Lua specific named parameter support)In addition to client side, the library also supports server side request
parsing, where we utilize HAProxy Lua API for all heavy lifting (i.e. HAProxy
handles client side connections, parses the headers and gives us access to
request body).Usage
-----After downloading this library, you will need to move it into your Lua package
package path, to be able to use it from your script. In later HAProxy versions,
there is a ``lua-prepend-path`` directive which can make your life easier.Basic usage for parsing client requests, constructing responses, or sending
custom requests to external servers is demonstrated bellow. You can use this in
your own Lua actions or services:.. code-block:: lua
local http = require('http')
local function main(applet)
-- 1) Parse client side request and print received headers
local req = http.request.parse(applet)
for k, v in req:get_headers() do
core.Debug(k .. ": " .. v)
end-- You can also parse submitted form data
local form, err = req:parse_multipart()-- 2) Send request to external server (please note there is no DNS
-- support for Lua on HAProxylocal res, err = http.get{url="http://1.2.3.4",
headers={host="example.net", ["x-test"]={"a", "b"}}
}if res then
for k, v in res:get_headers() do
core.Debug(k .. ": " .. v)
end
-- We can access the response body in content attribute
core.Debug(res.content)
else
core.Debug(err)
end-- 3) Send response to client side
http.response.create{status_code=200, content="Hello World"}:send(applet)end
core.register_service("test", "http", main)
Naturally, you need to add your script to main haproxy configuration::
global
...
lua-load test.luafrontend test
...
http-request use-service lua.test