summaryrefslogtreecommitdiff
path: root/admin.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2021-05-19 10:27:25 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2021-05-19 10:27:25 -0600
commit7f26a6b3e507cef98c2d4a74384bacf53bc58f57 (patch)
tree0c24a7b1d9151fb7bbb4f4d42389b6b1660cd8ca /admin.go
parent2aefe156869851a89d7a34e28c3e4ff3ac442fff (diff)
admin: Reinstate internal redirect for /id/ requests
Fix regression from ab80ff4fd2911afc394b9dbceeb9f71c7a0b7ec1 (probably a mistake when rebasing) See https://caddy.community/t/id-selector-is-not-working-after-upgrade-to-2-4-0/12513?u=matt
Diffstat (limited to 'admin.go')
-rw-r--r--admin.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/admin.go b/admin.go
index da7ce0f..51eb0cc 100644
--- a/admin.go
+++ b/admin.go
@@ -717,6 +717,10 @@ func (h adminHandler) handleError(w http.ResponseWriter, r *http.Request, err er
if err == nil {
return
}
+ if err == errInternalRedir {
+ h.serveHTTP(w, r)
+ return
+ }
apiErr, ok := err.(APIError)
if !ok {
@@ -896,7 +900,7 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error {
parts = append([]string{expanded}, parts[3:]...)
r.URL.Path = path.Join(parts...)
- return nil
+ return errInternalRedir
}
func handleStop(w http.ResponseWriter, r *http.Request) error {
@@ -1199,6 +1203,13 @@ var idRegexp = regexp.MustCompile(`(?m),?\s*"` + idKey + `"\s*:\s*(-?[0-9]+(\.[0
// pidfile is the name of the pidfile, if any.
var pidfile string
+// errInternalRedir indicates an internal redirect
+// and is useful when admin API handlers rewrite
+// the request; in that case, authentication and
+// authorization needs to happen again for the
+// rewritten request.
+var errInternalRedir = fmt.Errorf("internal redirect; re-authorization required")
+
const (
rawConfigKey = "config"
idKey = "@id"