-
Notifications
You must be signed in to change notification settings - Fork 606
Closed
Description
Describe the bug
ctx.ClientIP()
can't parse X-Forwarded-For
while using Unix Domain Sock.
To Reproduce
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/config"
)
func main() {
options := []config.Option{
server.WithHostPorts("ingress.sock"),
server.WithNetwork("unix"),
}
h := server.Default(options...)
h.GET("/hello", func(c context.Context, ctx *app.RequestContext) {
clientIp := ctx.ClientIP()
ctx.JSON(200, map[string]any{
"header": ctx.Request.Header.Get("X-Forwarded-For"),
"client_ip": clientIp,
})
})
h.Spin()
}
run socat
to emulate a nginx:
socat TCP-LISTEN:12345 UNIX-CONNECT:ingress.sock
Expected behavior
header
= client_ip
in the response body.
Screenshots
Hertz version:
v0.9.5
Metadata
Metadata
Assignees
Labels
No labels