Skip to content

Commit

Permalink
Merge pull request #1413 from headlamp-k8s/fix-issue-with-compressed-…
Browse files Browse the repository at this point in the history
…external-proxy-data

backend: Decrompress data from external-proxy when needed
  • Loading branch information
illume authored Sep 28, 2023
2 parents 17bc6ba + f65bf2b commit 840d05a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion backend/cmd/headlamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"compress/gzip"
"context"
"crypto/tls"
"encoding/base64"
Expand Down Expand Up @@ -491,7 +492,22 @@ func createHeadlampHandler(config *HeadlampConfig) http.Handler {
http.Error(w, err.Error(), http.StatusBadGateway)
return
}
respBody, err := io.ReadAll(resp.Body)
defer resp.Body.Close()

// Check that the server actually sent compressed data
var reader io.ReadCloser
switch resp.Header.Get("Content-Encoding") {
case "gzip":
reader, err = gzip.NewReader(resp.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer reader.Close()
default:
reader = resp.Body
}
respBody, err := io.ReadAll(reader)
if err != nil {
http.Error(w, err.Error(), http.StatusBadGateway)
return
Expand Down

0 comments on commit 840d05a

Please sign in to comment.