summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-03-12 15:25:49 -0500
committerGitHub <noreply@github.com>2021-03-12 13:25:49 -0700
commit0d7fe36007d5fbadaa6057b6543500d63147e6c0 (patch)
tree748b591a07fecede95e5fdcca0a53e93010c9af6 /caddyconfig
parentf137b82227f7b32b2ca036a89068c806a29a5ac7 (diff)
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
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/builtins.go11
-rw-r--r--caddyconfig/httpcaddyfile/directives.go1
2 files changed, 12 insertions, 0 deletions
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