summaryrefslogtreecommitdiffhomepage
path: root/util/httpm
diff options
context:
space:
mode:
authorNick Khyl <nickk@tailscale.com>2024-12-05 13:16:48 -0600
committerNick Khyl <nickk@tailscale.com>2024-12-05 13:16:48 -0600
commit0267fe83b200f1702a2fa0a395442c02a053fadb (patch)
tree63654c55225eeb834de59a5a0bc8d19033c6145b /util/httpm
parent87546a5edf6b6503a87eeb2d666baba57398a066 (diff)
downloadtailscale-1.78.0.tar.xz
tailscale-1.78.0.zip
VERSION.txt: this is v1.78.0v1.78.0
Signed-off-by: Nick Khyl <nickk@tailscale.com>
Diffstat (limited to 'util/httpm')
-rw-r--r--util/httpm/httpm.go72
-rw-r--r--util/httpm/httpm_test.go74
2 files changed, 73 insertions, 73 deletions
diff --git a/util/httpm/httpm.go b/util/httpm/httpm.go
index a9a691b8a..05292f0fa 100644
--- a/util/httpm/httpm.go
+++ b/util/httpm/httpm.go
@@ -1,36 +1,36 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-// Package httpm has shorter names for HTTP method constants.
-//
-// Some background: originally Go didn't have http.MethodGet, http.MethodPost
-// and life was good and people just wrote readable "GET" and "POST". But then
-// in a moment of weakness Brad and others maintaining net/http caved and let
-// the http.MethodFoo constants be added and code's been less readable since.
-// Now the substance of the method name is hidden away at the end after
-// "http.Method" and they all blend together and it's hard to read code using
-// them.
-//
-// This package is a compromise. It provides constants, but shorter and closer
-// to how it used to look. It does violate Go style
-// (https://github.com/golang/go/wiki/CodeReviewComments#mixed-caps) that says
-// constants shouldn't be SCREAM_CASE. But this isn't INT_MAX; it's GET and
-// POST, which are already defined as all caps.
-//
-// It would be tempting to make these constants be typed but then they wouldn't
-// be assignable to things in net/http that just want string. Oh well.
-package httpm
-
-const (
- GET = "GET"
- HEAD = "HEAD"
- POST = "POST"
- PUT = "PUT"
- PATCH = "PATCH"
- DELETE = "DELETE"
- CONNECT = "CONNECT"
- OPTIONS = "OPTIONS"
- TRACE = "TRACE"
- SPACEJUMP = "SPACEJUMP" // https://www.w3.org/Protocols/HTTP/Methods/SpaceJump.html
- BREW = "BREW" // https://datatracker.ietf.org/doc/html/rfc2324#section-2.1.1
-)
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+// Package httpm has shorter names for HTTP method constants.
+//
+// Some background: originally Go didn't have http.MethodGet, http.MethodPost
+// and life was good and people just wrote readable "GET" and "POST". But then
+// in a moment of weakness Brad and others maintaining net/http caved and let
+// the http.MethodFoo constants be added and code's been less readable since.
+// Now the substance of the method name is hidden away at the end after
+// "http.Method" and they all blend together and it's hard to read code using
+// them.
+//
+// This package is a compromise. It provides constants, but shorter and closer
+// to how it used to look. It does violate Go style
+// (https://github.com/golang/go/wiki/CodeReviewComments#mixed-caps) that says
+// constants shouldn't be SCREAM_CASE. But this isn't INT_MAX; it's GET and
+// POST, which are already defined as all caps.
+//
+// It would be tempting to make these constants be typed but then they wouldn't
+// be assignable to things in net/http that just want string. Oh well.
+package httpm
+
+const (
+ GET = "GET"
+ HEAD = "HEAD"
+ POST = "POST"
+ PUT = "PUT"
+ PATCH = "PATCH"
+ DELETE = "DELETE"
+ CONNECT = "CONNECT"
+ OPTIONS = "OPTIONS"
+ TRACE = "TRACE"
+ SPACEJUMP = "SPACEJUMP" // https://www.w3.org/Protocols/HTTP/Methods/SpaceJump.html
+ BREW = "BREW" // https://datatracker.ietf.org/doc/html/rfc2324#section-2.1.1
+)
diff --git a/util/httpm/httpm_test.go b/util/httpm/httpm_test.go
index 0c71edc2f..cbe327d95 100644
--- a/util/httpm/httpm_test.go
+++ b/util/httpm/httpm_test.go
@@ -1,37 +1,37 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-package httpm
-
-import (
- "os"
- "os/exec"
- "path/filepath"
- "strings"
- "testing"
-)
-
-func TestUsedConsistently(t *testing.T) {
- dir, err := os.Getwd()
- if err != nil {
- t.Fatal(err)
- }
- rootDir := filepath.Join(dir, "../..")
-
- // If we don't have a .git directory, we're not in a git checkout (e.g.
- // a downstream package); skip this test.
- if _, err := os.Stat(filepath.Join(rootDir, ".git")); err != nil {
- t.Skipf("skipping test since .git doesn't exist: %v", err)
- }
-
- cmd := exec.Command("git", "grep", "-l", "-F", "http.Method")
- cmd.Dir = rootDir
- matches, _ := cmd.Output()
- for _, fn := range strings.Split(strings.TrimSpace(string(matches)), "\n") {
- switch fn {
- case "util/httpm/httpm.go", "util/httpm/httpm_test.go":
- continue
- }
- t.Errorf("http.MethodFoo constant used in %s; use httpm.FOO instead", fn)
- }
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+package httpm
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+func TestUsedConsistently(t *testing.T) {
+ dir, err := os.Getwd()
+ if err != nil {
+ t.Fatal(err)
+ }
+ rootDir := filepath.Join(dir, "../..")
+
+ // If we don't have a .git directory, we're not in a git checkout (e.g.
+ // a downstream package); skip this test.
+ if _, err := os.Stat(filepath.Join(rootDir, ".git")); err != nil {
+ t.Skipf("skipping test since .git doesn't exist: %v", err)
+ }
+
+ cmd := exec.Command("git", "grep", "-l", "-F", "http.Method")
+ cmd.Dir = rootDir
+ matches, _ := cmd.Output()
+ for _, fn := range strings.Split(strings.TrimSpace(string(matches)), "\n") {
+ switch fn {
+ case "util/httpm/httpm.go", "util/httpm/httpm_test.go":
+ continue
+ }
+ t.Errorf("http.MethodFoo constant used in %s; use httpm.FOO instead", fn)
+ }
+}