Module: PudimServer.pipeline
HTTP handler pipeline with chained execution.
Pipeline.new()
Creates a new empty pipeline instance.
Inputs: no parameters.
Output: Pipeline instance.
local Pipeline = require("PudimServer.pipeline")
local pipeline = Pipeline.new()
Pipeline:use(entry)
Registers a handler at the end of the execution chain.
Inputs: entry (table with name and Handler(req,res,next)).
Output: no meaningful return value (internal registration).
pipeline:use{
name = "logger",
Handler = function(req, res, next)
print(req.method, req.path)
return next()
end
}
Pipeline:remove(name)
Removes a handler by name and returns true when found.
Inputs: name (string).
Output: boolean indicating removal status.
local removed = pipeline:remove("logger")
print("removed?", removed)
Pipeline:execute(req, res, finalHandler)
Executes handlers sequentially and finishes with finalHandler.
Inputs: req, res, finalHandler (final function).
Output: pipeline/final handler response (typically an HTTP string).
local result = pipeline:execute(req, res, function()
return res:response(200, "ok")
end)
print(result)
PipelineEntry
Shape of the table passed to Pipeline:use(entry) and server:UseHandler(entry).
| Field | Type | Description |
|---|---|---|
| name | string | Unique identifier used by remove(name) to unregister the handler. |
| Handler | function(req, res, next) | Callback executed during the pipeline. Call next() to continue to the next handler, or return a response string to short-circuit. |
local entry = {
name = "auth",
Handler = function(req, res, next)
if not req.headers["authorization"] then
return res:response(401, "Unauthorized")
end
return next()
end
}
pipeline:use(entry)