Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
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
Matthew Holt committed
May 19, 2021 at 10:27 UTC
7f26a6b3e507cef98c2d4a74384bacf53bc58f57
1 file changed
+12
-1
admin.go
+12
-1
@@ -717,6 +717,10 @@ func (h adminHandler) handleError(w http.ResponseWriter, r *http.Request, err er
717
if err == nil {
718
return
719
}
720
+ if err == errInternalRedir {
721
+ h.serveHTTP(w, r)
722
+ return
723
+ }
724
725
apiErr, ok := err.(APIError)
726
if !ok {
@@ -896,7 +900,7 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error {
900
parts = append([]string{expanded}, parts[3:]...)
901
r.URL.Path = path.Join(parts...)
902
899
- return nil
903
+ return errInternalRedir
904
}
905
906
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
1203
// pidfile is the name of the pidfile, if any.
1204
var pidfile string
1205
1206
+// errInternalRedir indicates an internal redirect
1207
+// and is useful when admin API handlers rewrite
1208
+// the request; in that case, authentication and
1209
+// authorization needs to happen again for the
1210
+// rewritten request.
1211
+var errInternalRedir = fmt.Errorf("internal redirect; re-authorization required")
1212
+
1213
const (
1214
rawConfigKey = "config"
1215
idKey = "@id"