safer, more idiomatic proxy helper (#32732)
Co-authored-by: Sofia Papagiannaki <sofia@grafana.com>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
4527f712e0
commit
8b8fc293b7
@@ -4,7 +4,9 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -86,9 +88,19 @@ type AlertingProxy struct {
|
||||
// withReq proxies a different request
|
||||
func (p *AlertingProxy) withReq(
|
||||
ctx *models.ReqContext,
|
||||
req *http.Request,
|
||||
method string,
|
||||
u *url.URL,
|
||||
body io.Reader,
|
||||
extractor func([]byte) (interface{}, error),
|
||||
headers map[string]string,
|
||||
) response.Response {
|
||||
req, err := http.NewRequest(method, u.String(), body)
|
||||
if err != nil {
|
||||
return response.Error(400, err.Error(), nil)
|
||||
}
|
||||
for h, v := range headers {
|
||||
req.Header.Add(h, v)
|
||||
}
|
||||
newCtx, resp := replacedResponseWriter(ctx)
|
||||
newCtx.Req.Request = req
|
||||
p.DataProxy.ProxyDatasourceRequestWithID(newCtx, ctx.ParamsInt64("Recipient"))
|
||||
|
||||
Reference in New Issue
Block a user