mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-17 14:12:16 +08:00
Merge efddcf406ae3c1e759701fb5b9dafee07e550bd3 into 713c3697f44fcb1b43291682133fc42d08a15f31
This commit is contained in:
commit
c5f239f4a1
16
context.go
16
context.go
@ -351,11 +351,11 @@ func (c *Context) BindWith(obj interface{}, b binding.Binding) error {
|
|||||||
// X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy.
|
// X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy.
|
||||||
func (c *Context) ClientIP() string {
|
func (c *Context) ClientIP() string {
|
||||||
if c.engine.ForwardedByClientIP {
|
if c.engine.ForwardedByClientIP {
|
||||||
clientIP := strings.TrimSpace(c.requestHeader("X-Real-Ip"))
|
clientIP := strings.TrimSpace(c.RequestHeader("X-Real-Ip"))
|
||||||
if len(clientIP) > 0 {
|
if len(clientIP) > 0 {
|
||||||
return clientIP
|
return clientIP
|
||||||
}
|
}
|
||||||
clientIP = c.requestHeader("X-Forwarded-For")
|
clientIP = c.RequestHeader("X-Forwarded-For")
|
||||||
if index := strings.IndexByte(clientIP, ','); index >= 0 {
|
if index := strings.IndexByte(clientIP, ','); index >= 0 {
|
||||||
clientIP = clientIP[0:index]
|
clientIP = clientIP[0:index]
|
||||||
}
|
}
|
||||||
@ -380,14 +380,12 @@ func (c *Context) ClientIP() string {
|
|||||||
|
|
||||||
// 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"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) requestHeader(key string) string {
|
// RequestHeader returns the value for the respective header key, or "" if not existent.
|
||||||
if values, _ := c.Request.Header[key]; len(values) > 0 {
|
func (c *Context) RequestHeader(key string) string {
|
||||||
return values[0]
|
return c.Request.Header.Get(key)
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
@ -573,7 +571,7 @@ func (c *Context) NegotiateFormat(offered ...string) string {
|
|||||||
assert1(len(offered) > 0, "you must provide at least one offer")
|
assert1(len(offered) > 0, "you must provide at least one offer")
|
||||||
|
|
||||||
if c.Accepted == nil {
|
if c.Accepted == nil {
|
||||||
c.Accepted = parseAccept(c.requestHeader("Accept"))
|
c.Accepted = parseAccept(c.RequestHeader("Accept"))
|
||||||
}
|
}
|
||||||
if len(c.Accepted) == 0 {
|
if len(c.Accepted) == 0 {
|
||||||
return offered[0]
|
return offered[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user