class

Azu::HandlerPipeline

Inherits Reference < Object

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

Build the handler chain

Returns the first handler in the chain with all handlers linked together. Raises if the pipeline is empty.

Source
build?

Build the handler chain, returning nil if empty

Source
clear

Clear all handlers from the pipeline

Source
empty?

Returns true if no handlers have been added

Source
size

Returns the number of handlers in the pipeline

Source
use(handler : HTTP::Handler) : self

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.

Source
use

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" }
Source
use_if(condition : Bool, handler : HTTP::Handler) : self

Add a handler conditionally

The handler is only added if the condition is true.

Example:

pipeline.use_if(ENV["ENABLE_CORS"]? == "true", cors_handler)
Source

Nested types