From 8b3e41da2987f0ea224513eb3bdeeb8e7f7906c7 Mon Sep 17 00:00:00 2001 From: phith0n <phith0n.ph2f@gmail.com> Date: Sun, 25 Dec 2022 04:55:31 +0800 Subject: [PATCH] feat: added FromTrustProxy function to gin.Context --- context.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/context.go b/context.go index 737e4d7a..8f09da22 100644 --- a/context.go +++ b/context.go @@ -814,6 +814,15 @@ func (c *Context) RemoteIP() string { return ip } +// FromTrustProxy check if the request is from a trusted proxy server +func (c *Context) FromTrustProxy() bool { + remoteIP := net.ParseIP(c.RemoteIP()) + if remoteIP == nil { + return false + } + return c.engine.isTrustedProxy(remoteIP) +} + // ContentType returns the Content-Type header of the request. func (c *Context) ContentType() string { return filterFlags(c.requestHeader("Content-Type"))