Skip to content

Commit

Permalink
refactor for switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisstocuz committed Oct 21, 2021
1 parent 4307d83 commit 40b9838
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
10 changes: 1 addition & 9 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,16 +743,8 @@ func (c *Context) ClientIP() string {
switch c.engine.TrustedPlatform {
case "":
// TrustedPlatform is empty, do nothing
case PlatformGoogleAppEngine:
if addr := c.requestHeader("X-Appengine-Remote-Addr"); addr != "" {
return addr
}
case PlatformCloudflare:
if addr := c.requestHeader("CF-Connecting-IP"); addr != "" {
return addr
}
default:
// Developers can define their own header of Trusted Platform
// Developers can define their own header of Trusted Platform or use predefined constants
if addr := c.requestHeader(c.engine.TrustedPlatform); addr != "" {
return addr
}
Expand Down
4 changes: 2 additions & 2 deletions gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ type RoutesInfo []RouteInfo
const (
// When running on Google App Engine. Trust X-Appengine-Remote-Addr
// for determining the client's IP
PlatformGoogleAppEngine = "google-app-engine"
PlatformGoogleAppEngine = "X-Appengine-Remote-Addr"
// When using Cloudflare's CDN. Trust CF-Connecting-IP for determining
// the client's IP
PlatformCloudflare = "cloudflare"
PlatformCloudflare = "CF-Connecting-IP"
)

// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
Expand Down

0 comments on commit 40b9838

Please sign in to comment.