From 4a5ad21b27e9b249972a9185dc94f4bf868f715a Mon Sep 17 00:00:00 2001 From: rawleyIfowler Date: Thu, 3 Mar 2022 13:21:26 -0600 Subject: [PATCH] fix: issue with capturing correct client ip --- controllers/blog.go | 2 +- main.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/blog.go b/controllers/blog.go index 258ae23..407bb7f 100644 --- a/controllers/blog.go +++ b/controllers/blog.go @@ -118,7 +118,7 @@ func CreateComment(c *gin.Context) { } db.Create(&comment) // Something was wrong with c.ClientIP() with trusted?? Weird. - recentPosters[c.Request.Header.Get("X-Forwarded-For")]++ + recentPosters[c.ClientIP()]++ // Pass the associated post to the template to add to the href c.HTML(http.StatusOK, "comment_post.tmpl", CommentDto{Url: comment.AssociatedPost}) } diff --git a/main.go b/main.go index bee1d58..e0d49da 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ func main() { router.SetFuncMap(funcMap) // This needs to change because of RCCTL in OpenBSD, not sure if you can use a ksh variable as path in Gin but i'll test router.LoadHTMLGlob("templates/*.tmpl") + router.TrustedPlatform = "X-Real-Ip" bootstrap.InitializeRoutes(router) router.Run(":8080") }