Skip to content

fix: call BlackWordsFn list func per request instead of once at setup - #57

Closed
MrBeldum wants to merge 1 commit into
go-pkgz:masterfrom
MrBeldum:fix-blackwordsfn-per-request
Closed

MrBeldum wants to merge 1 commit into
go-pkgz:masterfrom
MrBeldum:fix-blackwordsfn-per-request

Conversation

@MrBeldum

@MrBeldum MrBeldum commented Oct 5, 2026

Copy link
Copy Markdown

BlackWordsFn is documented as using a func to get the word list, but it called fn() once when the middleware was constructed and then behaved exactly like BlackWords with a frozen list. Any runtime change to the list (e.g. reloaded config) was silently ignored.

This change moves the body-inspection logic into a shared internal blackWords(func() []string) helper:

  • BlackWords(words...) wraps the static slice in a closure (behaviour unchanged).
  • BlackWordsFn(fn) now calls fn on every request, so updates are picked up.

Added TestBlackwordsFnDynamic, which changes the list after the middleware is created and checks that the next requests use the new list. It fails on the current code and passes with this change. go test -race ./... and go vet pass.

@MrBeldum
MrBeldum requested a review from umputun as a code owner October 5, 2026 21:37
@umputun umputun closed this Oct 6, 2026
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

Successfully merging this pull request may close these issues.

2 participants