aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-10-17 14:48:35 +0200
committerGitHub <noreply@github.com>2022-10-17 14:48:35 +0200
commit07bfb791ca616bd3a4aa96691b74c96146d59d90 (patch)
tree1556cfeea59114ec94ca0906f5eb9db6b136056b /clientapi
parentd72d4f8d5d0016a8dcbf77aba92671f3469eb630 (diff)
Scope transactions to endpoints (#2799)
To avoid returning results from e.g. `/redact` on `/sendToDevice` requests. Takes the raw URL path and uses `filepath.Dir` to remove the `txnID` (file) from it. Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/routing/redaction.go9
-rw-r--r--clientapi/routing/sendevent.go4
-rw-r--r--clientapi/routing/sendtodevice.go7
-rw-r--r--clientapi/routing/server_notices.go7
4 files changed, 15 insertions, 12 deletions
diff --git a/clientapi/routing/redaction.go b/clientapi/routing/redaction.go
index 27f0ba5d..a0f3b115 100644
--- a/clientapi/routing/redaction.go
+++ b/clientapi/routing/redaction.go
@@ -19,6 +19,9 @@ import (
"net/http"
"time"
+ "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/util"
+
"github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/internal/eventutil"
@@ -26,8 +29,6 @@ import (
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
- "github.com/matrix-org/gomatrixserverlib"
- "github.com/matrix-org/util"
)
type redactionContent struct {
@@ -51,7 +52,7 @@ func SendRedaction(
if txnID != nil {
// Try to fetch response from transactionsCache
- if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID); ok {
+ if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID, req.URL); ok {
return *res
}
}
@@ -144,7 +145,7 @@ func SendRedaction(
// Add response to transactionsCache
if txnID != nil {
- txnCache.AddTransaction(device.AccessToken, *txnID, &res)
+ txnCache.AddTransaction(device.AccessToken, *txnID, req.URL, &res)
}
return res
diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go
index 85f1053f..114e9088 100644
--- a/clientapi/routing/sendevent.go
+++ b/clientapi/routing/sendevent.go
@@ -86,7 +86,7 @@ func SendEvent(
if txnID != nil {
// Try to fetch response from transactionsCache
- if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID); ok {
+ if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID, req.URL); ok {
return *res
}
}
@@ -206,7 +206,7 @@ func SendEvent(
}
// Add response to transactionsCache
if txnID != nil {
- txnCache.AddTransaction(device.AccessToken, *txnID, &res)
+ txnCache.AddTransaction(device.AccessToken, *txnID, req.URL, &res)
}
// Take a note of how long it took to generate the event vs submit
diff --git a/clientapi/routing/sendtodevice.go b/clientapi/routing/sendtodevice.go
index 4a5f0888..0c022793 100644
--- a/clientapi/routing/sendtodevice.go
+++ b/clientapi/routing/sendtodevice.go
@@ -16,12 +16,13 @@ import (
"encoding/json"
"net/http"
+ "github.com/matrix-org/util"
+
"github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/clientapi/producers"
"github.com/matrix-org/dendrite/internal/transactions"
userapi "github.com/matrix-org/dendrite/userapi/api"
- "github.com/matrix-org/util"
)
// SendToDevice handles PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}
@@ -33,7 +34,7 @@ func SendToDevice(
eventType string, txnID *string,
) util.JSONResponse {
if txnID != nil {
- if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID); ok {
+ if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID, req.URL); ok {
return *res
}
}
@@ -63,7 +64,7 @@ func SendToDevice(
}
if txnID != nil {
- txnCache.AddTransaction(device.AccessToken, *txnID, &res)
+ txnCache.AddTransaction(device.AccessToken, *txnID, req.URL, &res)
}
return res
diff --git a/clientapi/routing/server_notices.go b/clientapi/routing/server_notices.go
index 9edeed2f..7729eddd 100644
--- a/clientapi/routing/server_notices.go
+++ b/clientapi/routing/server_notices.go
@@ -21,7 +21,6 @@ import (
"net/http"
"time"
- "github.com/matrix-org/dendrite/roomserver/version"
"github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/tokens"
@@ -29,6 +28,8 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
+ "github.com/matrix-org/dendrite/roomserver/version"
+
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
"github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
@@ -73,7 +74,7 @@ func SendServerNotice(
if txnID != nil {
// Try to fetch response from transactionsCache
- if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID); ok {
+ if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID, req.URL); ok {
return *res
}
}
@@ -251,7 +252,7 @@ func SendServerNotice(
}
// Add response to transactionsCache
if txnID != nil {
- txnCache.AddTransaction(device.AccessToken, *txnID, &res)
+ txnCache.AddTransaction(device.AccessToken, *txnID, req.URL, &res)
}
// Take a note of how long it took to generate the event vs submit