mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
chore: support underscores in agent bin filenames (#5496)
This commit is contained in:
+8
-1
@@ -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{
|
||||
|
||||
@@ -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("")},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user