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

fix(http_server): handle remote address of abstract unix domain socket #831

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions pkg/server/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ func (h *HttpHandler) warnErr(req *http.Request, msg string, err error) {
}

func (h *HttpHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
addrPort, err := netip.ParseAddrPort(req.RemoteAddr)
if err != nil {
h.logger.Error("failed to parse request remote addr", zap.String("addr", req.RemoteAddr), zap.Error(err))
w.WriteHeader(http.StatusInternalServerError)
return
var clientAddr netip.Addr
if req.RemoteAddr == "@" {
// listening to abstract UNIX domain socket, mark as local
clientAddr = netip.MustParseAddr("127.0.0.1")
} else {
addrPort, err := netip.ParseAddrPort(req.RemoteAddr)
if err != nil {
h.logger.Error("failed to parse request remote addr", zap.String("addr", req.RemoteAddr), zap.Error(err))
w.WriteHeader(http.StatusInternalServerError)
return
}
clientAddr = addrPort.Addr()
}
clientAddr := addrPort.Addr()

// read remote addr from header
if header := h.srcIPHeader; len(header) != 0 {
Expand Down