diff options
author | Matt Holt <mholt@users.noreply.github.com> | 2019-10-10 11:27:45 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-10 11:27:45 -0600 |
commit | b38365ff3b6ab8b2c474603fa0603831e7eff2a7 (patch) | |
tree | 7a35ea901e4ce8d3fbe028e8fc81bd1f69c6be68 /admin.go | |
parent | 53dd600b4de0c2b169f1eb4450a0f02950912524 (diff) | |
parent | 26cc8837084f9cea6057e9908f0b5bde0eb15d3e (diff) |
Merge pull request #2799 from caddyserver/v2-enterprise-merge
v2: Merge enterprise code into open source v2 branch
Diffstat (limited to 'admin.go')
-rw-r--r-- | admin.go | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -87,7 +87,7 @@ func StartAdmin(initialConfigJSON []byte) error { return fmt.Errorf("parsing admin listener address: %v", err) } if len(listenAddrs) != 1 { - return fmt.Errorf("admin endpoint must have exactly one listener; cannot listen on %v", listenAddrs) + return fmt.Errorf("admin endpoint must have exactly one address; cannot listen on %v", listenAddrs) } ln, err := net.Listen(netw, listenAddrs[0]) if err != nil { @@ -120,7 +120,7 @@ func StartAdmin(initialConfigJSON []byte) error { ReadTimeout: 5 * time.Second, ReadHeaderTimeout: 5 * time.Second, IdleTimeout: 5 * time.Second, - MaxHeaderBytes: 1024 * 256, + MaxHeaderBytes: 1024 * 64, } go cfgEndptSrv.Serve(ln) @@ -169,14 +169,11 @@ type AdminRoute struct { } func handleLoadConfig(w http.ResponseWriter, r *http.Request) { - r.Close = true if r.Method != http.MethodPost { http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) return } - var payload io.Reader = r.Body - // if the config is formatted other than Caddy's native // JSON, we need to adapt it before loading it if ctHeader := r.Header.Get("Content-Type"); ctHeader != "" { @@ -215,16 +212,15 @@ func handleLoadConfig(w http.ResponseWriter, r *http.Request) { } w.Write(respBody) } - payload = bytes.NewReader(result) + // replace original request body with adapted JSON + r.Body.Close() + r.Body = ioutil.NopCloser(bytes.NewReader(result)) } } - err := Load(payload) - if err != nil { - log.Printf("[ADMIN][ERROR] loading config: %v", err) - http.Error(w, err.Error(), http.StatusBadRequest) - return - } + // pass this off to the /config/ endpoint + r.URL.Path = "/" + rawConfigKey + "/" + handleConfig(w, r) } func handleStop(w http.ResponseWriter, r *http.Request) { |