From 4a46e43ce7dc0597b775a36df35af6dd33a05a6f Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sat, 4 Mar 2023 00:22:17 +0100 Subject: [PATCH] added head requests to sitemaps --- main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 34c5bca..4132faf 100644 --- a/main.go +++ b/main.go @@ -1059,7 +1059,13 @@ func getSiteMapIndex(c *gin.Context) { return } - c.Data(http.StatusOK, "application/xml", res) + if c.Request.Method == http.MethodHead { + c.Header("Content-Length", strconv.Itoa(len(res))) + c.Header("Content-Type", "application/xml") + c.Status(http.StatusOK) + } else { + c.Data(http.StatusOK, "application/xml", res) + } } func getSiteMap(c *gin.Context) { @@ -1085,7 +1091,13 @@ func getSiteMap(c *gin.Context) { return } - c.Data(http.StatusOK, "application/xml", res) + if c.Request.Method == http.MethodHead { + c.Header("Content-Length", strconv.Itoa(len(res))) + c.Header("Content-Type", "application/xml") + c.Status(http.StatusOK) + } else { + c.Data(http.StatusOK, "application/xml", res) + } } /* @@ -1253,7 +1265,9 @@ func main() { r.GET("/matches", getMatches) r.GET("/matches/next/:time", getMatches) r.GET("/sitemap.xml", getSiteMapIndex) + r.HEAD("/sitemap.xml", getSiteMapIndex) r.GET("/sitemap/:id", getSiteMap) + r.HEAD("/sitemap/:id", getSiteMap) log.Info("Start listening...")