Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the trailling slash for every requests #3760

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ func openWebapp(c echo.Context) error {

// WebappsRoutes sets the routing for the web apps service
func WebappsRoutes(router *echo.Group) {
router.GET("/", listWebappsHandler)
router.GET("", listWebappsHandler)
router.GET("/:slug", getHandler(consts.WebappType))
router.POST("/:slug", installHandler(consts.WebappType))
router.PUT("/:slug", updateHandler(consts.WebappType))
Expand All @@ -818,7 +818,7 @@ func WebappsRoutes(router *echo.Group) {

// KonnectorRoutes sets the routing for the konnectors service
func KonnectorRoutes(router *echo.Group) {
router.GET("/", listKonnectorsHandler)
router.GET("", listKonnectorsHandler)
router.GET("/:slug", getHandler(consts.KonnectorType))
router.POST("/:slug", installHandler(consts.KonnectorType))
router.PUT("/:slug", updateHandler(consts.KonnectorType))
Expand Down
10 changes: 5 additions & 5 deletions web/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestAuth(t *testing.T) {
t.Run("HomeWhenNotLoggedIn", func(t *testing.T) {
e := testutils.CreateTestClient(t, ts.URL)

e.GET("/").
e.GET("").
WithHost(domain).
WithRedirectPolicy(httpexpect.DontFollowRedirects).
Expect().Status(303).
Expand All @@ -135,7 +135,7 @@ func TestAuth(t *testing.T) {
t.Run("HomeWhenNotLoggedInWithJWT", func(t *testing.T) {
e := testutils.CreateTestClient(t, ts.URL)

e.GET("/").WithQuery("jwt", "foobar").
e.GET("").WithQuery("jwt", "foobar").
WithHost(domain).
WithRedirectPolicy(httpexpect.DontFollowRedirects).
Expect().Status(303).
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestAuth(t *testing.T) {
t.Run("HomeWhenLoggedIn", func(t *testing.T) {
e := testutils.CreateTestClient(t, ts.URL)

e.GET("/").
e.GET("").
WithHost(domain).
WithRedirectPolicy(httpexpect.DontFollowRedirects).
WithCookie(session.CookieName(testInstance), sessionID).
Expand Down Expand Up @@ -1896,7 +1896,7 @@ func TestAuth(t *testing.T) {
require.False(t, inst.OnboardingFinished)

// Should redirect to /auth/passphrase
e.GET("/").
e.GET("").
WithQuery("registerToken", hex.EncodeToString(inst.RegisterToken)).
WithHost(inst.Domain).
WithRedirectPolicy(httpexpect.DontFollowRedirects).
Expand All @@ -1914,7 +1914,7 @@ func TestAuth(t *testing.T) {

inst.OnboardingFinished = true

e.GET("/").
e.GET("").
WithQuery("registerToken", hex.EncodeToString(inst.RegisterToken)).
WithHost(domain).
WithRedirectPolicy(httpexpect.DontFollowRedirects).
Expand Down
2 changes: 0 additions & 2 deletions web/compat/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ func Compat(c echo.Context) error {
func Routes(router *echo.Group) {
router.GET("", Compat)
router.HEAD("", Compat)
router.GET("/", Compat)
router.HEAD("/", Compat)
}
6 changes: 3 additions & 3 deletions web/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func Routes(router *echo.Group) {
router.Use(couchdbStyleErrorHandler)

// API Routes that don't depend on a doctype
router.GET("/", dataAPIWelcome)
router.GET("", dataAPIWelcome)
router.GET("/_all_doctypes", allDoctypes)

// API Routes under /:doctype
Expand All @@ -576,7 +576,7 @@ func Routes(router *echo.Group) {
group.GET("/:docid", getDoc)
group.PUT("/:docid", UpdateDoc)
group.DELETE("/:docid", DeleteDoc)
group.POST("/", createDoc)
group.POST("", createDoc)
group.GET("/_all_docs", allDocs)
group.POST("/_all_docs", allDocs)
group.GET("/_normal_docs", normalDocs)
Expand All @@ -588,5 +588,5 @@ func Routes(router *echo.Group) {
group.POST("/_design/:designdocid/copy", copyDesignDoc)
group.DELETE("/_design/:designdocid", deleteDesignDoc)

group.DELETE("/", DeleteDatabase)
group.DELETE("", DeleteDatabase)
}
4 changes: 2 additions & 2 deletions web/data/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ func dbStatus(c echo.Context) error {
}

func replicationRoutes(group *echo.Group) {
group.PUT("/", createDB)
group.PUT("", createDB)

// Routes used only for replication
group.GET("/", dbStatus)
group.GET("", dbStatus)
group.GET("/_changes", changesFeed)
// POST=GET+filter see http://docs.couchdb.org/en/stable/api/database/changes.html#post--db-_changes)
group.POST("/_changes", changesFeed)
Expand Down
4 changes: 2 additions & 2 deletions web/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -1839,9 +1839,9 @@ func Routes(router *echo.Group) {

router.PATCH("/metadata", ModifyMetadataByPathHandler)
router.PATCH("/:file-id", ModifyMetadataByIDHandler)
router.PATCH("/", ModifyMetadataByIDInBatchHandler)
router.PATCH("", ModifyMetadataByIDInBatchHandler)

router.POST("/", CreationHandler)
router.POST("", CreationHandler)
router.POST("/:file-id", CreationHandler)
router.PUT("/:file-id", OverwriteFileContentHandler)
router.POST("/upload/metadata", UploadMetadataHandler)
Expand Down
2 changes: 1 addition & 1 deletion web/realtime/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,6 @@ func Notify(c echo.Context) error {

// Routes set the routing for the realtime service
func Routes(router *echo.Group) {
router.GET("/", Ws)
router.GET("", Ws)
router.POST("/:doctype/:id", Notify)
}
1 change: 0 additions & 1 deletion web/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func proxyMaintenanceReq(c echo.Context) error {
func Routes(router *echo.Group) {
gzip := middleware.Gzip()
router.GET("", proxyListReq, gzip)
router.GET("/", proxyListReq, gzip)
router.GET("/maintenance", proxyMaintenanceReq, gzip)
router.GET("/:app", proxyAppReq, gzip)
router.GET("/:app/icon", proxyReq(authed, shortClientCache, registry.NoCache))
Expand Down
2 changes: 1 addition & 1 deletion web/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func SetupRoutes(router *echo.Echo) error {
middlewares.CheckInstanceDeleting,
}

router.GET("/", auth.Home, mws...)
router.GET("", auth.Home, mws...)
auth.Routes(router.Group("/auth", mws...))
public.Routes(router.Group("/public", mws...))
wellknown.Routes(router.Group("/.well-known", mws...))
Expand Down
2 changes: 2 additions & 0 deletions web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func checkExists(filepath string) error {
// them.
func ListenAndServe() (*Servers, error) {
e := echo.New()
e.Pre(middleware.RemoveTrailingSlash())
e.HideBanner = true
e.HidePort = true

Expand All @@ -132,6 +133,7 @@ func ListenAndServe() (*Servers, error) {
}

admin := echo.New()
e.Pre(middleware.RemoveTrailingSlash())
admin.HideBanner = true
admin.HidePort = true

Expand Down
15 changes: 7 additions & 8 deletions web/sharings/replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,13 @@ func EndInitial(c echo.Context) error {

// replicatorRoutes sets the routing for the replicator
func replicatorRoutes(router *echo.Group) {
group := router.Group("", checkSharingPermissions)
group.POST("/:sharing-id/_revs_diff", RevsDiff, checkSharingWritePermissions)
group.POST("/:sharing-id/_bulk_docs", BulkDocs, checkSharingWritePermissions)
group.GET("/:sharing-id/io.cozy.files/:id", GetFolder, checkSharingReadPermissions)
group.PUT("/:sharing-id/io.cozy.files/:id/metadata", SyncFile, checkSharingWritePermissions)
group.PUT("/:sharing-id/io.cozy.files/:id", FileHandler, checkSharingWritePermissions)
group.POST("/:sharing-id/reupload", ReuploadHandler, checkSharingReadPermissions)
group.DELETE("/:sharing-id/initial", EndInitial, checkSharingWritePermissions)
router.POST("/:sharing-id/_revs_diff", RevsDiff, checkSharingPermissions, checkSharingWritePermissions)
router.POST("/:sharing-id/_bulk_docs", BulkDocs, checkSharingPermissions, checkSharingWritePermissions)
router.GET("/:sharing-id/io.cozy.files/:id", GetFolder, checkSharingPermissions, checkSharingReadPermissions)
router.PUT("/:sharing-id/io.cozy.files/:id/metadata", SyncFile, checkSharingPermissions, checkSharingWritePermissions)
router.PUT("/:sharing-id/io.cozy.files/:id", FileHandler, checkSharingPermissions, checkSharingWritePermissions)
router.POST("/:sharing-id/reupload", ReuploadHandler, checkSharingPermissions, checkSharingReadPermissions)
router.DELETE("/:sharing-id/initial", EndInitial, checkSharingPermissions, checkSharingWritePermissions)
}

func checkSharingReadPermissions(next echo.HandlerFunc) echo.HandlerFunc {
Expand Down
2 changes: 1 addition & 1 deletion web/sharings/sharings.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func localAvatar(c echo.Context, m sharing.Member) error {
// Routes sets the routing for the sharing service
func Routes(router *echo.Group) {
// Create a sharing
router.POST("/", CreateSharing) // On the sharer
router.POST("", CreateSharing) // On the sharer
router.PUT("/:sharing-id", PutSharing) // On a recipient
router.GET("/:sharing-id", GetSharing)
router.POST("/:sharing-id/answer", AnswerSharing)
Expand Down
2 changes: 0 additions & 2 deletions web/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,4 @@ func Status(c echo.Context) error {
func Routes(router *echo.Group) {
router.GET("", Status)
router.HEAD("", Status)
router.GET("/", Status)
router.HEAD("/", Status)
}
2 changes: 0 additions & 2 deletions web/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@ func Version(c echo.Context) error {
func Routes(router *echo.Group) {
router.GET("", Version)
router.HEAD("", Version)
router.GET("/", Version)
router.HEAD("/", Version)
}