Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseTrustedProxies not executed #2791

Closed
xcaptain opened this issue Jul 15, 2021 · 6 comments
Closed

parseTrustedProxies not executed #2791

xcaptain opened this issue Jul 15, 2021 · 6 comments

Comments

@xcaptain
Copy link

If not using app.Run to run a gin server,

gin/gin.go

Line 344 in caf2802

err = engine.parseTrustedProxies()

won't be executed. and will cause this line not executed

gin/context.go

Line 786 in caf2802

if c.engine.trustedCIDRs != nil {

Which will cause

gin/context.go

Line 735 in caf2802

func (c *Context) ClientIP() string {
not returning the correct ip adress.

I suggest moving this parseTrustedProxies to Default, so c.engine.trustedCIDRs won't be nil.

related issues: #2632

@zihengCat
Copy link
Contributor

What means not using app.Run to run a gin server? Could you give a quick code example?

@xcaptain
Copy link
Author

@zihengCat
image

using

http.ListenAndServe(":8080", router)

or

s.ListenAndServe()

won't execute .Run()

@zihengCat
Copy link
Contributor

zihengCat commented Jul 16, 2021

@xcaptain
Please waiting for the next release version which provides a SetTrustedProxies API for the purpose.

gin/gin.go

Lines 384 to 388 in 3116a2d

// SetTrustedProxies set Engine.TrustedProxies
func (engine *Engine) SetTrustedProxies(trustedProxies []string) error {
engine.TrustedProxies = trustedProxies
return engine.parseTrustedProxies()
}

@zihengCat
Copy link
Contributor

#2692

@xcaptain
Copy link
Author

Ok, thanks, but calling SetTrustedProxies every time before start the server is not convinent.

@zihengCat
Copy link
Contributor

@xcaptain
No, calling SetTrustedProxies outside is make sense.

Construct function New create a instance with default TrustedProxies field set. If user wants to change
TrustedProxies, calling another function outside instead of bundle it into initialization seems more suitable .

gin/gin.go

Line 177 in caf2802

TrustedProxies: []string{"0.0.0.0/0"},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants