Web / Caddy Server Interview questions
Explain the execution flow of Caddy's middleware chain?
Inside a matched route, Caddy's HTTP handlers behave like classic middleware: each one wraps the next, deciding whether to act before calling onward, after the call returns, or instead of calling onward at all.
Each handler implements a common interface with a method that receives the request and a reference to "the next handler." Non-terminal handlers, such as header or encode, typically do their work and then explicitly call that next handler, letting the chain continue. Terminal handlers, such as file_server, respond, or reverse_proxy, produce the actual response and don't call further down the chain. Because each handler wraps the next, the response also flows back up through the same handlers in reverse - which is how encode is able to compress a body that file_server produced further down the chain.
More Related questions...