Skip to content

Commit efd0965

Browse files
committed
just single slash
1 parent 3d43a72 commit efd0965

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

coderd/coderd.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"flag"
1111
"fmt"
1212
"io"
13+
"log"
1314
"net/http"
1415
"net/url"
1516
"path/filepath"
@@ -788,7 +789,7 @@ func New(options *Options) *API {
788789
httpmw.AttachRequestID,
789790
httpmw.ExtractRealIP(api.RealIPConfig),
790791
httpmw.Logger(api.Logger),
791-
stripSlashesMW,
792+
singleSlashMW,
792793
rolestore.CustomRoleMW,
793794
prometheusMW,
794795
// Build-Version is helpful for debugging.
@@ -1735,8 +1736,12 @@ func ReadExperiments(log slog.Logger, raw []string) codersdk.Experiments {
17351736

17361737
var multipleSlashesRe = regexp.MustCompile(`/+`)
17371738

1738-
func stripSlashesMW(next http.Handler) http.Handler {
1739+
func singleSlashMW(next http.Handler) http.Handler {
17391740
fn := func(w http.ResponseWriter, r *http.Request) {
1741+
if strings.Contains(r.URL.Path, "test-app-owner") {
1742+
log.Println(r.URL.Path)
1743+
}
1744+
17401745
var path string
17411746
rctx := chi.RouteContext(r.Context())
17421747
if rctx != nil && rctx.RoutePath != "" {
@@ -1748,11 +1753,6 @@ func stripSlashesMW(next http.Handler) http.Handler {
17481753
// Normalize multiple slashes to a single slash
17491754
newPath := multipleSlashesRe.ReplaceAllString(path, "/")
17501755

1751-
// Ensure it doesn't strip the root `/`
1752-
if len(newPath) > 1 && newPath[len(newPath)-1] == '/' {
1753-
newPath = strings.TrimSuffix(newPath, "/")
1754-
}
1755-
17561756
// Apply the cleaned path
17571757
if rctx != nil {
17581758
rctx.RoutePath = newPath

coderd/coderd_internal_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ func TestStripSlashesMW(t *testing.T) {
1919
wantPath string
2020
}{
2121
{"No changes", "/api/v1/buildinfo", "/api/v1/buildinfo"},
22-
{"Single trailing slash", "/api/v2/buildinfo/", "/api/v2/buildinfo"},
2322
{"Double slashes", "/api//v2//buildinfo", "/api/v2/buildinfo"},
24-
{"Triple slashes", "/api///v2///buildinfo///", "/api/v2/buildinfo"},
23+
{"Triple slashes", "/api///v2///buildinfo", "/api/v2/buildinfo"},
2524
{"Leading slashes", "///api/v2/buildinfo", "/api/v2/buildinfo"},
2625
{"Root path", "/", "/"},
2726
{"Double slashes root", "//", "/"},
@@ -46,7 +45,7 @@ func TestStripSlashesMW(t *testing.T) {
4645
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))
4746

4847
// Pass the request through the middleware
49-
stripSlashesMW(handler).ServeHTTP(rec, req)
48+
singleSlashMW(handler).ServeHTTP(rec, req)
5049

5150
// Get the updated chi RouteContext after middleware processing
5251
updatedCtx := chi.RouteContext(req.Context())

0 commit comments

Comments
 (0)