Skip to content

Commit

Permalink
Check Content-type header to set it correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Jul 15, 2024
1 parent 10414c0 commit 4f18a83
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"log"
"math/rand"
"mime"
"net"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -152,6 +153,16 @@ func reverseProxy(targetURL string, w http.ResponseWriter, r *http.Request) {
// for k, v := range resp.Header {
// w.Header()[k] = v
// }

// Check the Content-Type header and set it correctly if necessary
if resp.Header.Get("Content-Type") == "" || strings.Contains(r.URL.Path, "wmstats") {
ext := filepath.Ext(resp.Request.URL.Path)
mimeType := mime.TypeByExtension(ext)
if mimeType != "" {
resp.Header.Set("Content-Type", mimeType)
}
}

// create gzip reader if response is in gzip data-format
body := resp.Body
defer resp.Body.Close()
Expand Down

0 comments on commit 4f18a83

Please sign in to comment.