diff --git a/cmd/infra/stcrashreceiver/main.go b/cmd/infra/stcrashreceiver/main.go index a7f3c442b..6c434147e 100644 --- a/cmd/infra/stcrashreceiver/main.go +++ b/cmd/infra/stcrashreceiver/main.go @@ -118,7 +118,7 @@ func handleFailureFn(dsn, failureDir string, ignore *ignorePatterns) func(w http bs, err := io.ReadAll(lr) req.Body.Close() if err != nil { - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -130,7 +130,7 @@ func handleFailureFn(dsn, failureDir string, ignore *ignorePatterns) func(w http var reports []ur.FailureReport err = json.Unmarshal(bs, &reports) if err != nil { - http.Error(w, err.Error(), 400) + http.Error(w, err.Error(), http.StatusBadRequest) return } if len(reports) == 0 { @@ -141,7 +141,7 @@ func handleFailureFn(dsn, failureDir string, ignore *ignorePatterns) func(w http version, err := build.ParseVersion(reports[0].Version) if err != nil { - http.Error(w, err.Error(), 400) + http.Error(w, err.Error(), http.StatusBadRequest) return } for _, r := range reports { diff --git a/cmd/syncthing/cli/config.go b/cmd/syncthing/cli/config.go index f862416cc..79cde4848 100644 --- a/cmd/syncthing/cli/config.go +++ b/cmd/syncthing/cli/config.go @@ -10,6 +10,7 @@ import ( "encoding/json" "errors" "fmt" + "net/http" "reflect" "github.com/AudriusButkevicius/recli" @@ -86,7 +87,7 @@ func (h *configHandler) configAfter(_ *cli.Context) error { if err != nil { return err } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { body, err := responseToBArray(resp) if err != nil { return err diff --git a/cmd/syncthing/cli/errors.go b/cmd/syncthing/cli/errors.go index d3fee56cb..c17e00c38 100644 --- a/cmd/syncthing/cli/errors.go +++ b/cmd/syncthing/cli/errors.go @@ -9,6 +9,7 @@ package cli import ( "errors" "fmt" + "net/http" "strings" "github.com/alecthomas/kong" @@ -34,7 +35,7 @@ func (e *errorsPushCommand) Run(ctx Context) error { if err != nil { return err } - if response.StatusCode != 200 { + if response.StatusCode != http.StatusOK { errStr = fmt.Sprint("Failed to push error\nStatus code: ", response.StatusCode) bytes, err := responseToBArray(response) if err != nil { diff --git a/cmd/syncthing/cli/operations.go b/cmd/syncthing/cli/operations.go index 82dbee85c..569d1b00a 100644 --- a/cmd/syncthing/cli/operations.go +++ b/cmd/syncthing/cli/operations.go @@ -10,6 +10,7 @@ import ( "bufio" "errors" "fmt" + "net/http" "path/filepath" "github.com/alecthomas/kong" @@ -63,7 +64,7 @@ func (f *folderOverrideCommand) Run(ctx Context) error { if err != nil { return err } - if response.StatusCode != 200 { + if response.StatusCode != http.StatusOK { errStr := fmt.Sprint("Failed to override changes\nStatus code: ", response.StatusCode) bytes, err := responseToBArray(response) if err != nil { diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index ed20c0332..6618a77ec 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -388,8 +388,8 @@ func upgradeViaRest() error { } u.Path = path.Join(u.Path, "rest/system/upgrade") target := u.String() - r, _ := http.NewRequest("POST", target, nil) - r.Header.Set("X-API-Key", cfg.GUI().APIKey) + r, _ := http.NewRequest(http.MethodPost, target, nil) + r.Header.Set("X-Api-Key", cfg.GUI().APIKey) tr := &http.Transport{ DialContext: dialer.DialContext, @@ -407,7 +407,7 @@ func upgradeViaRest() error { defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { bs, err := io.ReadAll(resp.Body) if err != nil { return err diff --git a/lib/api/api.go b/lib/api/api.go index 2682638c6..6791123f9 100644 --- a/lib/api/api.go +++ b/lib/api/api.go @@ -546,7 +546,7 @@ func corsMiddleware(next http.Handler, allowFrameLoading bool) http.Handler { // See https://www.w3.org/TR/cors/ for details. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Process OPTIONS requests - if r.Method == "OPTIONS" { + if r.Method == http.MethodOptions { // Add a generous access-control-allow-origin header for CORS requests w.Header().Add("Access-Control-Allow-Origin", "*") // Only GET/POST/OPTIONS Methods are supported @@ -557,7 +557,7 @@ func corsMiddleware(next http.Handler, allowFrameLoading bool) http.Handler { w.Header().Set("Access-Control-Max-Age", "600") // Indicate that no content will be returned - w.WriteHeader(204) + w.WriteHeader(http.StatusNoContent) return } diff --git a/lib/rc/rc.go b/lib/rc/rc.go index e218c33d3..7386ffac0 100644 --- a/lib/rc/rc.go +++ b/lib/rc/rc.go @@ -173,7 +173,7 @@ func (p *Process) Get(path string) ([]byte, error) { } url := fmt.Sprintf("http://%s%s", p.addr, path) - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err } @@ -198,7 +198,7 @@ func (p *Process) Post(path string, data io.Reader) ([]byte, error) { }, } url := fmt.Sprintf("http://%s%s", p.addr, path) - req, err := http.NewRequest("POST", url, data) + req, err := http.NewRequest(http.MethodPost, url, data) if err != nil { return nil, err } @@ -397,7 +397,7 @@ func (*Process) readResponse(resp *http.Response) ([]byte, error) { if err != nil { return bs, err } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return bs, errors.New(resp.Status) } return bs, nil diff --git a/lib/relay/client/dynamic.go b/lib/relay/client/dynamic.go index 7b73e7eba..fc18104d5 100644 --- a/lib/relay/client/dynamic.go +++ b/lib/relay/client/dynamic.go @@ -48,7 +48,7 @@ func (c *dynamicClient) serve(ctx context.Context) error { l.Debugln(c, "looking up dynamic relays") - req, err := http.NewRequestWithContext(ctx, "GET", uri.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri.String(), nil) if err != nil { l.Debugln(c, "failed to lookup dynamic relays", err) return err diff --git a/lib/upgrade/upgrade_supported.go b/lib/upgrade/upgrade_supported.go index 6fb8e43f4..d64dd3b10 100644 --- a/lib/upgrade/upgrade_supported.go +++ b/lib/upgrade/upgrade_supported.go @@ -222,7 +222,7 @@ func upgradeToURL(archiveName, binary string, url string) error { func readRelease(archiveName, dir, url string) (string, error) { l.Debugf("loading %q", url) - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return "", err } diff --git a/lib/upnp/upnp.go b/lib/upnp/upnp.go index 432d410c2..6a0235ec4 100644 --- a/lib/upnp/upnp.go +++ b/lib/upnp/upnp.go @@ -578,7 +578,7 @@ func soapRequestWithIP(ctx context.Context, url, service, function, message stri body := fmt.Sprintf(template, message) - req, err := http.NewRequestWithContext(ctx, "POST", url, strings.NewReader(body)) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, strings.NewReader(body)) if err != nil { return resp, err } diff --git a/lib/ur/usage_report.go b/lib/ur/usage_report.go index eb7edca8a..28766bce7 100644 --- a/lib/ur/usage_report.go +++ b/lib/ur/usage_report.go @@ -366,7 +366,7 @@ func (s *Service) sendUsageReport(ctx context.Context) error { }, }, } - req, err := http.NewRequestWithContext(ctx, "POST", s.cfg.Options().URURL, &b) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.cfg.Options().URURL, &b) if err != nil { return err }