add debug Printf

This commit is contained in:
AJ ONeal 2020-11-23 12:01:53 -07:00
parent b2d6bb7a08
commit d91f2177f7
2 changed files with 19 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package http01proxy package http01proxy
import ( import (
"log"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
@ -24,14 +25,24 @@ func ListenAndServe(target string, timeout time.Duration) error {
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-Port")
req.Header.Del("X-Forwarded-Host")
// We want the incoming host header to remain unchanged,
// which is the domain name that is being challenged
log.Printf("[debug] Incoming Host: %q", req.Header.Get("Host"))
req.Header.Set("X-Forwarded-Host", 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
req.URL.Host = targetURL.Host req.URL.Host = targetURL.Host
req.Host = targetURL.Host //req.Host = targetURL.Host
//req.Header.Set("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 Path: %q", req.URL.Path)
log.Printf("[debug] Target 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
} else { } else {

View File

@ -44,6 +44,12 @@ func RouteStatic(r chi.Router) chi.Router {
func getACMEChallenges(w http.ResponseWriter, r *http.Request) { 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")
fmt.Printf("[debug] Host: %q\n[debug] X-Host: %q", host, xHost)
if len(xHost) > 0 {
// TODO TrustProxy option?
host = xHost
}
if strings.ContainsAny(host, "/:|\\") { if strings.ContainsAny(host, "/:|\\") {
host = "" host = ""
} }