From 79109f4965e4f94773886125ff039ab98b73ae43 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 11 Apr 2021 20:49:07 -0700 Subject: [PATCH] ipn/ipnlocal: use PATCH for EditPrefs, not POST Addendum to earlier 00d641d9fc69557fdac6500eb889088520010705. Reserve POST for SetPrefs in the future. Signed-off-by: Brad Fitzpatrick --- client/tailscale/tailscale.go | 2 +- ipn/localapi/localapi.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/tailscale/tailscale.go b/client/tailscale/tailscale.go index fb191141a..e386d7695 100644 --- a/client/tailscale/tailscale.go +++ b/client/tailscale/tailscale.go @@ -219,7 +219,7 @@ func EditPrefs(ctx context.Context, mp *ipn.MaskedPrefs) (*ipn.Prefs, error) { if err != nil { return nil, err } - body, err := send(ctx, "POST", "/localapi/v0/prefs", http.StatusOK, bytes.NewReader(mpj)) + body, err := send(ctx, "PATCH", "/localapi/v0/prefs", http.StatusOK, bytes.NewReader(mpj)) if err != nil { return nil, err } diff --git a/ipn/localapi/localapi.go b/ipn/localapi/localapi.go index 0e76e4504..2d8b7cabf 100644 --- a/ipn/localapi/localapi.go +++ b/ipn/localapi/localapi.go @@ -226,7 +226,8 @@ func (h *Handler) servePrefs(w http.ResponseWriter, r *http.Request) { return } var prefs *ipn.Prefs - if r.Method == "POST" { + switch r.Method { + case "PATCH": mp := new(ipn.MaskedPrefs) if err := json.NewDecoder(r.Body).Decode(mp); err != nil { http.Error(w, err.Error(), 400) @@ -238,8 +239,11 @@ func (h *Handler) servePrefs(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 400) return } - } else { + case "GET", "HEAD": prefs = h.b.Prefs() + default: + http.Error(w, "unsupported method", http.StatusMethodNotAllowed) + return } w.Header().Set("Content-Type", "application/json") e := json.NewEncoder(w)