Skip to content

fix(middleware): halt handler chain after writing error response - #3

Open
xkong2017 wants to merge 1 commit into
LiliannaBruflat83:mainfrom
xkong2017:fix-middleware-early-return
Open

xkong2017 wants to merge 1 commit into
LiliannaBruflat83:mainfrom
xkong2017:fix-middleware-early-return

Conversation

@xkong2017

Copy link
Copy Markdown

Summary

Ensures middleware returns immediately after writing a response so next.ServeHTTP is not called for rejected requests, preventing superfluous response.WriteHeader warnings and unintended downstream execution.

Changes

  • middleware/auth.go: AuthMiddleware writes the 401 response and returns immediately, halting the chain.
  • middleware/auth_test.go: tests verifying the downstream handler is bypassed on rejection and invoked on success.

Verification

go vet ./... clean; go test -race -v ./... passes (both tests).

Closes #1
/claim #1

Ensure middleware returns immediately after writing a response so
next.ServeHTTP is not called for rejected requests, preventing superfluous
WriteHeader warnings and unintended downstream execution.

Closes LiliannaBruflat83#1
/claim LiliannaBruflat83#1
@opirebot

opirebot Bot commented Aug 18, 2026

Copy link
Copy Markdown

😅 Unfortunately there are no rewards left to claim in this issue!

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.

🎯 Prevent Middleware Chain Execution After Writing Response / Calling http.Error

1 participant