From 0d7fe36007d5fbadaa6057b6543500d63147e6c0 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Fri, 12 Mar 2021 15:25:49 -0500 Subject: httpcaddyfile: Add `error` directive for the existing handler (#4034) * httpcaddyfile: Add `error` directive for the existing handler * httpcaddyfile: Move `error` to the end of the order --- caddyconfig/httpcaddyfile/builtins.go | 11 +++++++++++ caddyconfig/httpcaddyfile/directives.go | 1 + 2 files changed, 12 insertions(+) (limited to 'caddyconfig') diff --git a/caddyconfig/httpcaddyfile/builtins.go b/caddyconfig/httpcaddyfile/builtins.go index 8830f52..32f9da7 100644 --- a/caddyconfig/httpcaddyfile/builtins.go +++ b/caddyconfig/httpcaddyfile/builtins.go @@ -42,6 +42,7 @@ func init() { RegisterHandlerDirective("redir", parseRedir) RegisterHandlerDirective("respond", parseRespond) RegisterHandlerDirective("abort", parseAbort) + RegisterHandlerDirective("error", parseError) RegisterHandlerDirective("route", parseRoute) RegisterHandlerDirective("handle", parseHandle) RegisterDirective("handle_errors", parseHandleErrors) @@ -566,6 +567,16 @@ func parseAbort(h Helper) (caddyhttp.MiddlewareHandler, error) { return &caddyhttp.StaticResponse{Abort: true}, nil } +// parseError parses the error directive. +func parseError(h Helper) (caddyhttp.MiddlewareHandler, error) { + se := new(caddyhttp.StaticError) + err := se.UnmarshalCaddyfile(h.Dispenser) + if err != nil { + return nil, err + } + return se, nil +} + // parseRoute parses the route directive. func parseRoute(h Helper) (caddyhttp.MiddlewareHandler, error) { sr := new(caddyhttp.Subroute) diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index 7f77f49..b4a8407 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -70,6 +70,7 @@ var directiveOrder = []string{ "file_server", "acme_server", "abort", + "error", } // directiveIsOrdered returns true if dir is -- cgit v1.2.3