Skip to content

Commit ba367a3

Browse files
committed
add Content-Digest header to init script response
1 parent a4268ea commit ba367a3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

coderd/initscript.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package coderd
22

33
import (
4+
"crypto/sha256"
5+
"encoding/base64"
46
"fmt"
57
"net/http"
68
"strings"
@@ -34,7 +36,10 @@ func (api *API) initScript(rw http.ResponseWriter, r *http.Request) {
3436
script = strings.ReplaceAll(script, "${ACCESS_URL}", api.AccessURL.String()+"/")
3537
script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token")
3638

39+
scriptBytes := []byte(script)
40+
hash := sha256.Sum256(scriptBytes)
41+
rw.Header().Set("Content-Digest", fmt.Sprintf("sha256:%x", base64.StdEncoding.EncodeToString(hash[:])))
3742
rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
3843
rw.WriteHeader(http.StatusOK)
39-
_, _ = rw.Write([]byte(script))
44+
_, _ = rw.Write(scriptBytes)
4045
}

0 commit comments

Comments
 (0)