mirror of
https://github.com/gin-gonic/gin.git
synced 2025-04-24 10:20:28 +08:00
feat: added FromTrustProxy function to gin.Context
This commit is contained in:
parent
e868fd1d3d
commit
8b3e41da29
@ -814,6 +814,15 @@ func (c *Context) RemoteIP() string {
|
|||||||
return ip
|
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.
|
// ContentType returns the Content-Type header of the request.
|
||||||
func (c *Context) ContentType() string {
|
func (c *Context) ContentType() string {
|
||||||
return filterFlags(c.requestHeader("Content-Type"))
|
return filterFlags(c.requestHeader("Content-Type"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user