add debug Printf

This commit is contained in:
AJ ONeal 2020-11-23 12:21:51 -07:00
parent d91f2177f7
commit ea22b856de
2 changed files with 10 additions and 8 deletions

View File

@ -24,24 +24,26 @@ func ListenAndServe(target string, timeout time.Duration) error {
Director: func(req *http.Request) { Director: func(req *http.Request) {
req.Header.Del("X-Forwarded-For") req.Header.Del("X-Forwarded-For")
req.Header.Del("X-Forwarded-Proto") req.Header.Del("X-Forwarded-Proto")
req.Header.Del("X-Forwarded-Port")
req.Header.Del("X-Forwarded-Host") req.Header.Del("X-Forwarded-Host")
req.Header.Del("X-Forwarded-Port")
// We want the incoming host header to remain unchanged, // We want the incoming host header to remain unchanged,
// which is the domain name that is being challenged // which is the domain name that is being challenged
log.Printf("[debug] Incoming Host: %q", req.Header.Get("Host")) log.Printf("[debug] Incoming Host: %q", req.Host)
req.Header.Set("X-Forwarded-Host", req.Header.Get("Host")) log.Printf("[debug] Incoming URL.Host: %q", req.URL.Host)
log.Printf("[debug] Incoming Header.Host: %q", req.Header.Get("Host"))
targetQuery := targetURL.RawQuery targetQuery := targetURL.RawQuery
req.URL.Scheme = targetURL.Scheme req.URL.Scheme = targetURL.Scheme
// But we want the proxy target to be updated to the new target // But we want the proxy target to be updated to the new target
req.URL.Host = targetURL.Host
//req.Host = targetURL.Host //req.Host = targetURL.Host
req.URL.Host = targetURL.Host
req.URL.Path, req.URL.RawPath = joinURLPath(targetURL, req.URL) req.URL.Path, req.URL.RawPath = joinURLPath(targetURL, req.URL)
log.Printf("[debug] Target Host: %q", req.URL.Host) //log.Printf("[debug] Target Host: %q", req.Host)
log.Printf("[debug] Target Path: %q", req.URL.Path) log.Printf("[debug] Target URL.Host: %q", req.URL.Host)
log.Printf("[debug] Target RawPath: %q", req.URL.Path) log.Printf("[debug] Target URL.Path: %q", req.URL.Path)
log.Printf("[debug] Target URL.RawPath: %q", req.URL.Path)
if targetQuery == "" || req.URL.RawQuery == "" { if targetQuery == "" || req.URL.RawQuery == "" {
req.URL.RawQuery = targetQuery + req.URL.RawQuery req.URL.RawQuery = targetQuery + req.URL.RawQuery

View File

@ -45,7 +45,7 @@ func getACMEChallenges(w http.ResponseWriter, r *http.Request) {
//token := chi.URLParam(r, "token") //token := chi.URLParam(r, "token")
host := r.Host host := r.Host
xHost := r.Header.Get("X-Forwarded-Host") xHost := r.Header.Get("X-Forwarded-Host")
fmt.Printf("[debug] Host: %q\n[debug] X-Host: %q", host, xHost) log.Printf("[debug] Host: %q\n[debug] X-Host: %q", host, xHost)
if len(xHost) > 0 { if len(xHost) > 0 {
// TODO TrustProxy option? // TODO TrustProxy option?
host = xHost host = xHost