Azu::HandlerPipeline
Fluent builder for composing HTTP handler middleware pipelines
The HandlerPipeline provides a clean, chainable API for building middleware stacks. Handlers are executed in the order they are added.
Example:
pipeline = Azu::HandlerPipeline.new
.use(Azu::Handler::Rescuer.new)
.use(Azu::Handler::CORS.new(origins: ["https://example.com"]))
.use(Azu::Handler::CSRF.new)
.use { |ctx| puts "Request: #{ctx.request.path}" }
.build
# Use with HTTP::Server
server = HTTP::Server.new(pipeline) { |ctx| ... }
Instance methods
Build the handler chain
Returns the first handler in the chain with all handlers linked together. Raises if the pipeline is empty.
Add a handler to the pipeline
Handlers are executed in the order they are added.
Each handler should call call_next(context) to continue the chain.
Add a block-based handler to the pipeline
The block receives the HTTP context and should process the request. The next handler in the chain is called automatically after the block.
Example:
pipeline.use { |ctx| ctx.response.headers["X-Custom"] = "value" }
Add a handler conditionally
The handler is only added if the condition is true.
Example:
pipeline.use_if(ENV["ENABLE_CORS"]? == "true", cors_handler)