mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
parent
fe795417f7
commit
7c44dd713a
@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
const GrafanaRequestID = "X-Grafana-Request-Id"
|
const GrafanaRequestID = "X-Grafana-Request-Id"
|
||||||
const GrafanaSignedRequestID = "X-Grafana-Signed-Request-Id"
|
const GrafanaSignedRequestID = "X-Grafana-Signed-Request-Id"
|
||||||
|
const XRealIPHeader = "X-Real-Ip"
|
||||||
const GrafanaInternalRequest = "X-Grafana-Internal-Request"
|
const GrafanaInternalRequest = "X-Grafana-Internal-Request"
|
||||||
|
|
||||||
// NewHostedGrafanaACHeaderMiddleware creates a new plugins.ClientMiddleware that will
|
// NewHostedGrafanaACHeaderMiddleware creates a new plugins.ClientMiddleware that will
|
||||||
@ -83,6 +84,7 @@ func (m *HostedGrafanaACHeaderMiddleware) applyGrafanaRequestIDHeader(ctx contex
|
|||||||
if reqCtx != nil && reqCtx.Req != nil {
|
if reqCtx != nil && reqCtx.Req != nil {
|
||||||
remoteAddress := web.RemoteAddr(reqCtx.Req)
|
remoteAddress := web.RemoteAddr(reqCtx.Req)
|
||||||
if remoteAddress != "" {
|
if remoteAddress != "" {
|
||||||
|
h.SetHTTPHeader(XRealIPHeader, remoteAddress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,9 @@ func Test_HostedGrafanaACHeaderMiddleware(t *testing.T) {
|
|||||||
|
|
||||||
require.Equal(t, cdt.CallResourceReq.Headers[GrafanaSignedRequestID][0], computed)
|
require.Equal(t, cdt.CallResourceReq.Headers[GrafanaSignedRequestID][0], computed)
|
||||||
|
|
||||||
|
require.Len(t, cdt.CallResourceReq.Headers[XRealIPHeader], 1)
|
||||||
|
require.Equal(t, cdt.CallResourceReq.Headers[XRealIPHeader][0], "1.2.3.4")
|
||||||
|
|
||||||
// Internal header should not be set
|
// Internal header should not be set
|
||||||
require.Len(t, cdt.CallResourceReq.Headers[GrafanaInternalRequest], 0)
|
require.Len(t, cdt.CallResourceReq.Headers[GrafanaInternalRequest], 0)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user