Macaron: remove custom Request type (#37874)

* remove macaron.Request, use http.Request instead

* remove com dependency from bindings module

* fix another c.Req.Request
This commit is contained in:
Serge Zaitsev
2021-09-01 11:18:30 +02:00
committed by GitHub
parent 56f61001a8
commit c3ab2fdeb7
35 changed files with 1205 additions and 111 deletions

View File

@@ -59,9 +59,7 @@ func TestInitContextWithAuthProxy_CachedInvalidUserID(t *testing.T) {
require.NoError(t, err)
ctx := &models.ReqContext{
Context: &macaron.Context{
Req: macaron.Request{
Request: req,
},
Req: req,
Data: map[string]interface{}{},
},
Logger: log.New("Test"),

View File

@@ -64,11 +64,7 @@ func prepareMiddleware(t *testing.T, remoteCache *remotecache.RemoteCache, cb fu
}
ctx := &models.ReqContext{
Context: &macaron.Context{
Req: macaron.Request{
Request: req,
},
},
Context: &macaron.Context{Req: req},
}
auth := New(cfg, &Options{

View File

@@ -85,10 +85,10 @@ func (h *ContextHandler) Middleware(mContext *macaron.Context) {
}
// Inject ReqContext into a request context and replace the request instance in the macaron context
mContext.Req.Request = mContext.Req.WithContext(context.WithValue(mContext.Req.Context(), reqContextKey{}, reqContext))
mContext.Map(mContext.Req.Request)
mContext.Req = mContext.Req.WithContext(context.WithValue(mContext.Req.Context(), reqContextKey{}, reqContext))
mContext.Map(mContext.Req)
traceID, exists := cw.ExtractTraceID(mContext.Req.Request.Context())
traceID, exists := cw.ExtractTraceID(mContext.Req.Context())
if exists {
reqContext.Logger = reqContext.Logger.New("traceID", traceID)
}

View File

@@ -96,12 +96,8 @@ func initTokenRotationScenario(ctx context.Context, t *testing.T, ctxHdlr *Conte
return nil, nil, err
}
reqContext := &models.ReqContext{
Context: &macaron.Context{
Req: macaron.Request{
Request: req,
},
},
Logger: log.New("testlogger"),
Context: &macaron.Context{Req: req},
Logger: log.New("testlogger"),
}
mw := mockWriter{rr}

View File

@@ -60,7 +60,7 @@ func (p *DataSourceProxyService) ProxyDatasourceRequestWithID(c *models.ReqConte
return
}
err = p.PluginRequestValidator.Validate(ds.Url, c.Req.Request)
err = p.PluginRequestValidator.Validate(ds.Url, c.Req)
if err != nil {
c.JsonApiErr(http.StatusForbidden, "Access denied", err)
return

View File

@@ -280,9 +280,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
t.Helper()
t.Run(desc, func(t *testing.T) {
ctx := macaron.Context{
Req: macaron.Request{Request: &http.Request{}},
}
ctx := macaron.Context{Req: &http.Request{}}
orgID := int64(1)
role := models.ROLE_ADMIN
sqlStore := sqlstore.InitTestDB(t)

View File

@@ -715,9 +715,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
t.Helper()
t.Run(desc, func(t *testing.T) {
ctx := macaron.Context{
Req: macaron.Request{Request: &http.Request{}},
}
ctx := macaron.Context{Req: &http.Request{}}
cfg := setting.NewCfg()
orgID := int64(1)
role := models.ROLE_ADMIN

View File

@@ -282,8 +282,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
}
newCtx := centrifuge.SetCredentials(ctx.Req.Context(), cred)
newCtx = livecontext.SetContextSignedUser(newCtx, user)
r := ctx.Req.Request
r = r.WithContext(newCtx)
r := ctx.Req.WithContext(newCtx)
wsHandler.ServeHTTP(ctx.Resp, r)
}
@@ -291,8 +290,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
user := ctx.SignedInUser
newCtx := livecontext.SetContextSignedUser(ctx.Req.Context(), user)
newCtx = livecontext.SetContextStreamID(newCtx, ctx.Params(":streamId"))
r := ctx.Req.Request
r = r.WithContext(newCtx)
r := ctx.Req.WithContext(newCtx)
pushWSHandler.ServeHTTP(ctx.Resp, r)
}

View File

@@ -56,7 +56,7 @@ func (g *Gateway) Handle(ctx *models.ReqContext) {
urlValues := ctx.Req.URL.Query()
frameFormat := pushurl.FrameFormatFromValues(urlValues)
body, err := io.ReadAll(ctx.Req.Request.Body)
body, err := io.ReadAll(ctx.Req.Body)
if err != nil {
logger.Error("Error reading body", "error", err)
ctx.Resp.WriteHeader(http.StatusInternalServerError)

View File

@@ -372,7 +372,7 @@ func (srv AlertmanagerSrv) RoutePostTestReceivers(c *models.ReqContext, body api
ctx, cancelFunc, err := contextWithTimeoutFromRequest(
c.Req.Context(),
c.Req.Request,
c.Req,
defaultTestReceiversTimeout,
maxTestReceiversTimeout)
if err != nil {

View File

@@ -103,7 +103,7 @@ func (p *AlertingProxy) withReq(
req.Header.Add(h, v)
}
newCtx, resp := replacedResponseWriter(ctx)
newCtx.Req.Request = req
newCtx.Req = req
p.DataProxy.ProxyDatasourceRequestWithID(newCtx, ctx.ParamsInt64("Recipient"))
status := resp.Status()