From a3680c5e2a18970e095fcb2a711bb97b1c679df6 Mon Sep 17 00:00:00 2001
From: Travis Ralston <travpc@gmail.com>
Date: Wed, 9 Aug 2023 23:22:32 -0600
Subject: [PATCH] Set host on MMR test requests

---
 api/_routers/03-host_detection.go  | 2 +-
 test/test_internals/util_client.go | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/api/_routers/03-host_detection.go b/api/_routers/03-host_detection.go
index a5e2ffb5..620518e8 100644
--- a/api/_routers/03-host_detection.go
+++ b/api/_routers/03-host_detection.go
@@ -59,7 +59,7 @@ func (h *HostRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 			"action": GetActionName(r),
 			"method": r.Method,
 		}).Inc()
-		logger.Warn("The server name provided in the Host header is not configured, or the request was made directly to the media repo. Please specify a Host header and check your reverse proxy configuration. The request is being rejected.")
+		logger.Warnf("The server name provided ('%s') in the Host header is not configured, or the request was made directly to the media repo. Please specify a Host header and check your reverse proxy configuration. The request is being rejected.", r.Host)
 		w.WriteHeader(http.StatusBadGateway)
 		if b, err := json.Marshal(_responses.BadGatewayError("Review server logs to continue")); err != nil {
 			panic(errors.New("error preparing BadGatewayError: " + err.Error()))
diff --git a/test/test_internals/util_client.go b/test/test_internals/util_client.go
index 16d839bd..da21c630 100644
--- a/test/test_internals/util_client.go
+++ b/test/test_internals/util_client.go
@@ -65,6 +65,9 @@ func (c *MatrixClient) DoRaw(method string, endpoint string, qs url.Values, cont
 	if err != nil {
 		return nil, err
 	}
+	if c.ServerName != "" {
+		req.Host = c.ServerName
+	}
 	if contentType != "" {
 		req.Header.Set("Content-Type", contentType)
 	}
@@ -72,6 +75,6 @@ func (c *MatrixClient) DoRaw(method string, endpoint string, qs url.Values, cont
 		req.Header.Set("Authorization", "Bearer "+c.AccessToken)
 	}
 
-	log.Println(fmt.Sprintf("[HTTP] [Auth=%s] %s %s", c.AccessToken, req.Method, req.RequestURI))
+	log.Println(fmt.Sprintf("[HTTP] [Auth=%s] [Host=%s] %s %s", c.AccessToken, c.ServerName, req.Method, req.URL.String()))
 	return http.DefaultClient.Do(req)
 }
-- 
GitLab