Files
webhooker/internal/middleware/ratelimit.go
sneak b1eb2466f6
All checks were successful
check / check (push) Successful in 3m20s
Scan the X-Forwarded-For chain without splitting it (closes #133)
The 64-hop cap bounded the walk but not the allocation: the chain was
split before it was capped, so a padded header cost a []string
proportional to its whole length on every request to the
unauthenticated receiver.

Cut hops off the right end of each header value in place with
strings.LastIndexByte instead, and walk multiple header values in
reverse rather than joining them. Bucket assignment is unchanged: the
walk still counts every comma-separated entry against the cap, skips
empty ones, stops at the first hop that is not a trusted proxy, and
falls back to the peer on an unreadable hop or an exhausted cap.

Measured over a 1 MB chain: 1,606,043 bytes allocated per call before,
16 bytes after.
2026-08-12 10:04:55 +00:00

8.5 KiB