From 472defbfe6eda672f43fe86ded3a679086088f96 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Thu, 17 Aug 2017 11:55:01 +0100 Subject: [PATCH] Use single route for both cases --- .../dendrite/clientapi/routing/routing.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index f286b9b65..87a731228 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -17,6 +17,7 @@ package routing import ( "encoding/json" "net/http" + "strings" "github.com/gorilla/mux" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" @@ -93,18 +94,16 @@ func Setup( return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], vars["txnID"], nil, cfg, queryAPI, producer) }), ) - r0mux.Handle("/rooms/{roomID}/state/{eventType}", + r0mux.Handle("/rooms/{roomID}/state/{eventType:[a-z._-]+(?:\\/)?}", common.MakeAuthAPI("send_message", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) emptyString := "" - return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], vars["txnID"], &emptyString, cfg, queryAPI, producer) - }), - ) - r0mux.Handle("/rooms/{roomID}/state/{eventType}/", - common.MakeAuthAPI("send_message", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars := mux.Vars(req) - emptyString := "" - return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], vars["txnID"], &emptyString, cfg, queryAPI, producer) + eventType := vars["eventType"] + // If there's a trailing slash, remove it + if strings.HasSuffix(eventType, "/") { + eventType = eventType[:len(eventType)-1] + } + return writers.SendEvent(req, device, vars["roomID"], eventType, vars["txnID"], &emptyString, cfg, queryAPI, producer) }), ) r0mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",