mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-04-11 22:33:40 +00:00
Apply uncommitted changes from ptah
This commit is contained in:
parent
2c021484b7
commit
9606dd8ca1
2 changed files with 27 additions and 0 deletions
|
@ -13,6 +13,20 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
type statusCodeResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
statusCode int
|
||||
}
|
||||
|
||||
func NewStatusCodeResponseWriter(w http.ResponseWriter) *statusCodeResponseWriter {
|
||||
return &statusCodeResponseWriter{w, http.StatusOK}
|
||||
}
|
||||
|
||||
func (lrw *statusCodeResponseWriter) WriteHeader(code int) {
|
||||
lrw.statusCode = code
|
||||
lrw.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
// MakeAuthAPI turns a util.JSONRequestHandler function into an http.Handler which authenticates the request.
|
||||
func MakeAuthAPI(
|
||||
tracer opentracing.Tracer, metricsName string, data auth.Data,
|
||||
|
@ -24,6 +38,11 @@ func MakeAuthAPI(
|
|||
return *err
|
||||
}
|
||||
|
||||
// Add user information to opentracing span
|
||||
span := opentracing.SpanFromContext(req.Context())
|
||||
span.SetTag("matrix.user", device.UserID)
|
||||
span.SetTag("matrix.device", device.ID)
|
||||
|
||||
return f(req, device)
|
||||
}
|
||||
return MakeExternalAPI(tracer, metricsName, h)
|
||||
|
@ -36,8 +55,15 @@ func MakeExternalAPI(tracer opentracing.Tracer, metricsName string, f func(*http
|
|||
withSpan := func(w http.ResponseWriter, req *http.Request) {
|
||||
span := tracer.StartSpan(metricsName)
|
||||
defer span.Finish()
|
||||
|
||||
ext.HTTPUrl.Set(span, req.URL.String())
|
||||
ext.HTTPMethod.Set(span, req.Method)
|
||||
|
||||
req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span))
|
||||
rw := NewStatusCodeResponseWriter(w)
|
||||
|
||||
h.ServeHTTP(w, req)
|
||||
ext.HTTPStatusCode.Set(span, uint16(rw.statusCode))
|
||||
}
|
||||
|
||||
return http.HandlerFunc(withSpan)
|
||||
|
|
|
@ -61,6 +61,7 @@ func Setup(
|
|||
// {keyID} argument and always return a response containing all of the keys.
|
||||
v2keysmux.Handle("/server/{keyID}", localKeys).Methods(http.MethodGet)
|
||||
v2keysmux.Handle("/server/", localKeys).Methods(http.MethodGet)
|
||||
v2keysmux.Handle("/server", localKeys).Methods(http.MethodGet)
|
||||
|
||||
v1fedmux.Handle("/send/{txnID}/", common.MakeFedAPI(
|
||||
tracer, "federation_send", cfg.Matrix.ServerName, keys,
|
||||
|
|
Loading…
Reference in a new issue