@marcel91200 / caddy Mirror · read-only / commits / 0e204b73
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 22:00 UTC

admin: Respond with 4xx on non-existing config path (#5870)

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>

Norman Soetbeer committed Oct 11, 2023 at 22:24 UTC 0e204b730aa2b1fa0835336b1117eff8c420f713
2 files changed +20 -2
admin.go
+14 -2
@@ -1196,15 +1196,27 @@ traverseLoop:
1196 }
1197 case http.MethodPut:
1198 if _, ok := v[part]; ok {
1199 - return fmt.Errorf("[%s] key already exists: %s", path, part)
1199 + return APIError{
1200 + HTTPStatus: http.StatusConflict,
1201 + Err: fmt.Errorf("[%s] key already exists: %s", path, part),
1202 + }
1203 }
1204 v[part] = val
1205 case http.MethodPatch:
1206 if _, ok := v[part]; !ok {
1204 - return fmt.Errorf("[%s] key does not exist: %s", path, part)
1207 + return APIError{
1208 + HTTPStatus: http.StatusNotFound,
1209 + Err: fmt.Errorf("[%s] key does not exist: %s", path, part),
1210 + }
1211 }
1212 v[part] = val
1213 case http.MethodDelete:
1214 + if _, ok := v[part]; !ok {
1215 + return APIError{
1216 + HTTPStatus: http.StatusNotFound,
1217 + Err: fmt.Errorf("[%s] key does not exist: %s", path, part),
1218 + }
1219 + }
1220 delete(v, part)
1221 default:
1222 return fmt.Errorf("unrecognized method %s", method)
admin_test.go
+6
@@ -75,6 +75,12 @@ func TestUnsyncedConfigAccess(t *testing.T) {
75 path: "/bar/qq",
76 expect: `{"foo": "jet", "bar": {"aa": "bb"}, "list": ["a", "b", "c"]}`,
77 },
78 + {
79 + method: "DELETE",
80 + path: "/bar/qq",
81 + expect: `{"foo": "jet", "bar": {"aa": "bb"}, "list": ["a", "b", "c"]}`,
82 + shouldErr: true,
83 + },
84 {
85 method: "POST",
86 path: "/list",