chore: support underscores in agent bin filenames (#5496)

This commit is contained in:
Dean Sheather
2022-12-21 21:06:38 +00:00
committed by GitHub
parent bae69df8f9
commit 43b61ce33c
2 changed files with 10 additions and 1 deletions
+8 -1
View File
@@ -60,7 +60,14 @@ func Handler(siteFS fs.FS, binFS http.FileSystem) http.Handler {
}
mux := http.NewServeMux()
mux.Handle("/bin/", http.StripPrefix("/bin", http.FileServer(binFS)))
mux.Handle("/bin/", http.StripPrefix("/bin", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
// Convert underscores in the filename to hyphens. We eventually want to
// change our hyphen-based filenames to underscores, but we need to
// support both for now.
r.URL.Path = strings.ReplaceAll(r.URL.Path, "_", "-")
http.FileServer(binFS).ServeHTTP(rw, r)
})))
mux.Handle("/", http.FileServer(http.FS(siteFS))) // All other non-html static files.
return secureHeaders(&handler{
+2
View File
@@ -315,7 +315,9 @@ func TestServingBin(t *testing.T) {
},
},
reqs: []req{
// We support both hyphens and underscores for compatibility.
{url: "/bin/coder-linux-amd64", wantStatus: http.StatusOK, wantBody: []byte("embed")},
{url: "/bin/coder_linux_amd64", wantStatus: http.StatusOK, wantBody: []byte("embed")},
{url: "/bin/GITKEEP", wantStatus: http.StatusOK, wantBody: []byte("")},
},
},