mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 23:13:11 -06:00
mediaapi/routing: Make use of refactored request logging in util package
This commit is contained in:
parent
5d4432218b
commit
42a390f8fe
|
|
@ -15,10 +15,8 @@
|
||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/mediaapi/config"
|
"github.com/matrix-org/dendrite/mediaapi/config"
|
||||||
"github.com/matrix-org/dendrite/mediaapi/storage"
|
"github.com/matrix-org/dendrite/mediaapi/storage"
|
||||||
|
|
@ -29,11 +27,6 @@ import (
|
||||||
|
|
||||||
const pathPrefixR0 = "/_matrix/media/v1"
|
const pathPrefixR0 = "/_matrix/media/v1"
|
||||||
|
|
||||||
type contextKeys string
|
|
||||||
|
|
||||||
const ctxValueLogger = contextKeys("logger")
|
|
||||||
const ctxValueRequestID = contextKeys("requestid")
|
|
||||||
|
|
||||||
type downloadRequestHandler struct {
|
type downloadRequestHandler struct {
|
||||||
Config config.MediaAPI
|
Config config.MediaAPI
|
||||||
Database *storage.Database
|
Database *storage.Database
|
||||||
|
|
@ -41,21 +34,7 @@ type downloadRequestHandler struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler downloadRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (handler downloadRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
// NOTE: The code below is from util.MakeJSONAPI and respond but this is the
|
util.SetupRequestLogging(req)
|
||||||
// only API that needs a different form of it to be able to pass the
|
|
||||||
// http.ResponseWriter to the handler
|
|
||||||
reqID := util.RandomString(12)
|
|
||||||
// Set a Logger and request ID on the context
|
|
||||||
ctx := context.WithValue(req.Context(), ctxValueLogger, log.WithFields(log.Fields{
|
|
||||||
"req.method": req.Method,
|
|
||||||
"req.path": req.URL.Path,
|
|
||||||
"req.id": reqID,
|
|
||||||
}))
|
|
||||||
ctx = context.WithValue(ctx, ctxValueRequestID, reqID)
|
|
||||||
req = req.WithContext(ctx)
|
|
||||||
|
|
||||||
logger := util.GetLogger(req.Context())
|
|
||||||
logger.Print("Incoming request")
|
|
||||||
|
|
||||||
if req.Method == "OPTIONS" {
|
if req.Method == "OPTIONS" {
|
||||||
util.SetCORSHeaders(w)
|
util.SetCORSHeaders(w)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue