Skip to content

Commit 43b61ce

Browse files
authored
chore: support underscores in agent bin filenames (#5496)
1 parent bae69df commit 43b61ce

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

site/site.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ func Handler(siteFS fs.FS, binFS http.FileSystem) http.Handler {
6060
}
6161

6262
mux := http.NewServeMux()
63-
mux.Handle("/bin/", http.StripPrefix("/bin", http.FileServer(binFS)))
63+
mux.Handle("/bin/", http.StripPrefix("/bin", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
64+
// Convert underscores in the filename to hyphens. We eventually want to
65+
// change our hyphen-based filenames to underscores, but we need to
66+
// support both for now.
67+
r.URL.Path = strings.ReplaceAll(r.URL.Path, "_", "-")
68+
69+
http.FileServer(binFS).ServeHTTP(rw, r)
70+
})))
6471
mux.Handle("/", http.FileServer(http.FS(siteFS))) // All other non-html static files.
6572

6673
return secureHeaders(&handler{

site/site_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ func TestServingBin(t *testing.T) {
315315
},
316316
},
317317
reqs: []req{
318+
// We support both hyphens and underscores for compatibility.
318319
{url: "/bin/coder-linux-amd64", wantStatus: http.StatusOK, wantBody: []byte("embed")},
320+
{url: "/bin/coder_linux_amd64", wantStatus: http.StatusOK, wantBody: []byte("embed")},
319321
{url: "/bin/GITKEEP", wantStatus: http.StatusOK, wantBody: []byte("")},
320322
},
321323
},

0 commit comments

Comments
 (0)