mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
QueryData: fix header parsing to support expressions (#58826)
fixes #58821
This commit is contained in:
parent
9a5a344304
commit
934fb2f0ee
@ -259,6 +259,14 @@ func (pr parsedRequest) validateRequest() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pr.hasExpression {
|
||||||
|
hasExpr := pr.httpRequest.URL.Query().Get("expression")
|
||||||
|
if hasExpr == "" || hasExpr == "true" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return ErrQueryParamMismatch
|
||||||
|
}
|
||||||
|
|
||||||
vals := splitHeaders(pr.httpRequest.Header.Values(HeaderDatasourceUID))
|
vals := splitHeaders(pr.httpRequest.Header.Values(HeaderDatasourceUID))
|
||||||
count := len(vals)
|
count := len(vals)
|
||||||
if count > 0 { // header exists
|
if count > 0 { // header exists
|
||||||
|
@ -288,8 +288,16 @@ func TestQueryDataMultipleSources(t *testing.T) {
|
|||||||
HTTPRequest: nil,
|
HTTPRequest: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// without query parameter
|
||||||
_, err = tc.queryService.QueryData(context.Background(), tc.signedInUser, true, reqDTO)
|
_, err = tc.queryService.QueryData(context.Background(), tc.signedInUser, true, reqDTO)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
httpreq, _ := http.NewRequest(http.MethodPost, "http://localhost/ds/query?expression=true", bytes.NewReader([]byte{}))
|
||||||
|
httpreq.Header.Add("X-Datasource-Uid", "gIEkMvIVz")
|
||||||
|
reqDTO.HTTPRequest = httpreq
|
||||||
|
|
||||||
|
// with query parameter
|
||||||
|
_, err = tc.queryService.QueryData(context.Background(), tc.signedInUser, true, reqDTO)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user