Plugins: Refactor cleaning of call resource response headers (#67145)

First part of #66889 moving cleaning of call resource response headers 
within plugin management client.
This commit is contained in:
Marcus Efraimsson
2023-04-25 19:44:32 +02:00
committed by GitHub
parent a8b4a4bb45
commit 73920b1e34
10 changed files with 283 additions and 59 deletions
-17
View File
@@ -161,7 +161,6 @@ func (hs *HTTPServer) flushStream(stream callResourceClientResponseStream, w htt
// Expected that headers and status are only part of first stream
if processedStreams == 0 {
var hasContentType bool
for k, values := range resp.Headers {
// Convert the keys to the canonical format of MIME headers.
// This ensures that we can safely add/overwrite headers
@@ -169,15 +168,6 @@ func (hs *HTTPServer) flushStream(stream callResourceClientResponseStream, w htt
// and be sure they won't be present multiple times in the response.
k = textproto.CanonicalMIMEHeaderKey(k)
switch k {
case "Set-Cookie":
// Due to security reasons we don't want to forward
// cookies from a backend plugin to clients/browsers.
continue
case "Content-Type":
hasContentType = true
}
for _, v := range values {
// TODO: Figure out if we should use Set here instead
// nolint:gocritic
@@ -185,13 +175,6 @@ func (hs *HTTPServer) flushStream(stream callResourceClientResponseStream, w htt
}
}
// Make sure a content type always is returned in response
if !hasContentType && resp.Status != http.StatusNoContent {
w.Header().Set("Content-Type", "application/json")
}
proxyutil.SetProxyResponseHeaders(w.Header())
w.WriteHeader(resp.Status)
}