From b293c7c7754e4da40566236f4716f9e73e7c9d1c Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Wed, 21 Dec 2022 20:52:37 +0000 Subject: [PATCH] chore: support underscores in agent bin filenames --- site/site.go | 9 ++++++++- site/site_test.go | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/site/site.go b/site/site.go index 884f50a62482c..a06500b1c11fe 100644 --- a/site/site.go +++ b/site/site.go @@ -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{ diff --git a/site/site_test.go b/site/site_test.go index 6bddc7905b598..a4bf5eccafc69 100644 --- a/site/site_test.go +++ b/site/site_test.go @@ -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("")}, }, },