summaryrefslogtreecommitdiffhomepage
path: root/admin.go
diff options
context:
space:
mode:
authorjhwz <[email protected]>2022-07-13 06:23:55 +1200
committerGitHub <[email protected]>2022-07-12 12:23:55 -0600
commitad3a83fb9169899226ce12a61c16b5bf4d03c482 (patch)
tree62f19bf05422fe5844c9c90c73402b12f639a7a4 /admin.go
parent53c4d788d4bbc00d396be743a2c0b36482e53c6e (diff)
downloadcaddy-ad3a83fb9169899226ce12a61c16b5bf4d03c482.tar.gz
caddy-ad3a83fb9169899226ce12a61c16b5bf4d03c482.zip
admin: expect quoted ETags (#4879)v2.5.2
* expect quoted etags * admin: Minor refactor of etag facilities Co-authored-by: Matthew Holt <[email protected]>
Diffstat (limited to 'admin.go')
-rw-r--r--admin.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/admin.go b/admin.go
index e37caf83a..670a27017 100644
--- a/admin.go
+++ b/admin.go
@@ -21,7 +21,6 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/base64"
- "encoding/hex"
"encoding/json"
"errors"
"expvar"
@@ -901,6 +900,12 @@ func (h adminHandler) originAllowed(origin *url.URL) bool {
// produce and verify ETags.
func etagHasher() hash.Hash32 { return fnv.New32a() }
+// makeEtag returns an Etag header value (including quotes) for
+// the given config path and hash of contents at that path.
+func makeEtag(path string, hash hash.Hash) string {
+ return fmt.Sprintf(`"%s %x"`, path, hash.Sum(nil))
+}
+
func handleConfig(w http.ResponseWriter, r *http.Request) error {
switch r.Method {
case http.MethodGet:
@@ -919,7 +924,7 @@ func handleConfig(w http.ResponseWriter, r *http.Request) error {
// we could consider setting up a sync.Pool for the summed
// hashes to reduce GC pressure.
- w.Header().Set("ETag", r.URL.Path+" "+hex.EncodeToString(hash.Sum(nil)))
+ w.Header().Set("Etag", makeEtag(r.URL.Path, hash))
return nil