From 2ed48c54a5dffdaa22a72d336334d3495befecb3 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 20 Apr 2017 15:09:38 +0100 Subject: [PATCH] Add more stub endpoints --- .../dendrite/clientapi/readers/login.go | 5 -- .../dendrite/clientapi/routing/routing.go | 61 +++++++++++++++++++ vendor/manifest | 2 +- vendor/src/github.com/matrix-org/util/json.go | 5 ++ 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/login.go b/src/github.com/matrix-org/dendrite/clientapi/readers/login.go index faad732ad..36b81e57f 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/login.go +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/login.go @@ -63,11 +63,6 @@ func Login(req *http.Request, cfg config.ClientAPI) util.JSONResponse { HomeServer: cfg.ServerName, }, } - } else if req.Method == "OPTIONS" { - return util.JSONResponse{ - Code: 200, - JSON: nil, - } } return util.JSONResponse{ Code: 405, 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 18220dbd0..47eebc704 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -1,6 +1,7 @@ package routing import ( + "encoding/json" "net/http" "github.com/gorilla/mux" @@ -43,12 +44,72 @@ func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg config.ClientAPI return writers.SendEvent(req, vars["roomID"], vars["eventType"], vars["txnID"], &stateKey, cfg, queryAPI, producer) })), ) + + // Stub endpoints required by Riot + r0mux.Handle("/login", make("login", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { return readers.Login(req, cfg) })), ) + r0mux.Handle("/pushrules/", + make("push_rules", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { + res := json.RawMessage(`{ + "global": { + "content": [], + "override": [], + "room": [], + "sender": [], + "underride": [] + } + }`) + return util.JSONResponse{ + Code: 200, + JSON: &res, + } + })), + ) + + r0mux.Handle("/user/{userID}/filter", + make("make_filter", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { + return util.JSONResponse{ + Code: 200, + JSON: struct{}{}, + } + })), + ) + + r0mux.Handle("/user/{userID}/filter/{filterID}", + make("filter", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { + return util.JSONResponse{ + Code: 200, + JSON: struct{}{}, + } + })), + ) + + // Riot user settings + + r0mux.Handle("/profile/{userID}", + make("profile", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { + return util.JSONResponse{ + Code: 200, + JSON: struct{}{}, + } + })), + ) + + r0mux.Handle("/account/3pid", + make("account_3pid", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { + res := json.RawMessage(`{"threepids":[]}`) + return util.JSONResponse{ + Code: 200, + JSON: &res, + } + })), + ) + servMux.Handle("/metrics", prometheus.Handler()) servMux.Handle("/api/", http.StripPrefix("/api", apiMux)) } diff --git a/vendor/manifest b/vendor/manifest index dceb7916c..2cc75e575 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -98,7 +98,7 @@ { "importpath": "github.com/matrix-org/util", "repository": "https://github.com/matrix-org/util", - "revision": "ec8896cd7d9ba6de6143c5f123d1e45413657e7d", + "revision": "bc9d5e2d2f68a2ca279fce0fa2f28a91ecf301ed", "branch": "master" }, { diff --git a/vendor/src/github.com/matrix-org/util/json.go b/vendor/src/github.com/matrix-org/util/json.go index 3323b526b..a30d73f8e 100644 --- a/vendor/src/github.com/matrix-org/util/json.go +++ b/vendor/src/github.com/matrix-org/util/json.go @@ -111,6 +111,11 @@ func MakeJSONAPI(handler JSONRequestHandler) http.HandlerFunc { logger := GetLogger(req.Context()) logger.Print("Incoming request") + if req.Method == "OPTIONS" { + SetCORSHeaders(w) + w.WriteHeader(200) + return + } res := handler.OnIncomingRequest(req) // Set common headers returned regardless of the outcome of the request