fix(dialer): correct inverted setMark on FreeBSD/OpenBSD
Fix setMark early-return conditions that were inverted relative to Linux: on FreeBSD (SO_USER_COOKIE) and OpenBSD (SO_RTABLE), a non-zero mark was short-circuited instead of applied, disabling socket marking entirely. Also fix GetClientIP to trim leading whitespace from X-Forwarded-For entries (per RFC 7239), and fix Body.Read to subtract len(b) instead of n from recordSize when a single read exceeds the remaining quota. Add unit tests for internal/net/ (addr, dialer, http, ip, net, pipe, transport, resolve, proxyproto, udp).
This commit is contained in:
@@ -17,7 +17,7 @@ func GetClientIP(req *http.Request) net.IP {
|
||||
if sip == "" {
|
||||
ss := strings.Split(req.Header.Get("X-Forwarded-For"), ",")
|
||||
if len(ss) > 0 && ss[0] != "" {
|
||||
sip = ss[0]
|
||||
sip = strings.TrimSpace(ss[0])
|
||||
}
|
||||
}
|
||||
if sip == "" {
|
||||
@@ -53,7 +53,7 @@ func (p *Body) Read(b []byte) (n int, err error) {
|
||||
b = b[:p.recordSize]
|
||||
}
|
||||
p.buf.Write(b)
|
||||
p.recordSize -= n
|
||||
p.recordSize -= len(b)
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user