Skip to content

Commit

Permalink
Debug: wmstats MIME type
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Jul 15, 2024
1 parent 4cb5020 commit 8a60c4e
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 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 @@ -148,29 +149,22 @@ func reverseProxy(targetURL string, w http.ResponseWriter, r *http.Request) {
// Set the status code from the backend response
w.WriteHeader(resp.StatusCode)

// 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)
}
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
}

// Check the Content-Type header and set it correctly if necessary
// if resp.Header.Get("Content-Type") == "" || strings.Contains(r.URL.Path, "wmstats") {
if strings.Contains(r.URL.Path, "wmstats") {
ext := filepath.Ext(resp.Request.URL.Path)
mimeType := mime.TypeByExtension(ext)
log.Println("### path=", resp.Request.URL.Path, ext, mimeType)
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 8a60c4e

Please sign in to comment.