DataProxy: Fix issue overriding response body when response status is 101 (#41364)

When a request going through Grafana data source proxy responds with a websocket 
upgrade response we cannot override the response body since it produces an error. 
This problem seems to have been introduced in Grafana v8.0 by #38962. 
In addition #40303 added same problem.

Fixes #41292
This commit is contained in:
Marcus Efraimsson 2021-11-09 14:33:54 +01:00 committed by GitHub
parent cd5d84b0f3
commit 3be452f995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -96,7 +96,7 @@ func executeMiddleware(next http.RoundTripper, datasourceLabel prometheus.Labels
return nil, err
}
if res != nil {
if res != nil && res.StatusCode != http.StatusSwitchingProtocols {
res.Body = httpclient.CountBytesReader(res.Body, func(bytesRead int64) {
responseSizeSummary.Observe(float64(bytesRead))
})

View File

@ -21,7 +21,10 @@ func ResponseLimitMiddleware(limit int64) sdkhttpclient.Middleware {
return nil, err
}
res.Body = httpclient.MaxBytesReader(res.Body, limit)
if res != nil && res.StatusCode != http.StatusSwitchingProtocols {
res.Body = httpclient.MaxBytesReader(res.Body, limit)
}
return res, nil
})
})