From a41b65e952e1e2f44977dd5630ef147eea53e807 Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Fri, 15 May 2020 14:59:24 +0200
Subject: [PATCH] Test with replacing redirect in html body by host

---
 main.go | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/main.go b/main.go
index f1fddf6..fa40123 100644
--- a/main.go
+++ b/main.go
@@ -56,8 +56,20 @@ func main() {
 			if err != nil {
 				fmt.Println(err)
 			}
+			// Define the host
+			host := "https://" + r.Host
+			fmt.Println(host)
+			// Get the response body as a string
+			pageContentString := string(contents)
+			// Replace redirectUri by the host in the body
+			pageContentString = strings.ReplaceAll(pageContentString, redirectUri, host)
+			fmt.Println(pageContentString)
+			// Convert string to byte for response writting
+			newPageContentByte := []byte(pageContentString)
+
+			// fmt.Println(r.Host)
 			if response.StatusCode >= 200 && response.StatusCode <= 299 {
-				w.Write(contents)
+				w.Write(newPageContentByte)
 			} else {
 				http.Error(w, http.StatusText(response.StatusCode), response.StatusCode)
 			}
-- 
GitLab