Skip to content

Commit

Permalink
Debug: code changes for wmstats MIME type problem
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Jul 15, 2024
1 parent 4f18a83 commit 4cb5020
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"io"
"log"
"math/rand"
"mime"
"net"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -149,18 +148,27 @@ func reverseProxy(targetURL string, w http.ResponseWriter, r *http.Request) {
// Set the status code from the backend response
w.WriteHeader(resp.StatusCode)

// Copy headers from the backend response
// 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)
/*
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)
}
return nil
}
*/
if strings.Contains(r.URL.Path, "wmstats") {
// do not modify response body for wmstats requests
// TODO: investigation of wrong MIME type, e..g
// ... was not loaded because its MIME type, “text/plain”, is not “text/css”.
return nil
}

// Copy headers from the backend response
for k, v := range resp.Header {
w.Header()[k] = v
}

// create gzip reader if response is in gzip data-format
Expand Down

0 comments on commit 4cb5020

Please sign in to comment.