Skip to content

fix: resolve #1 - 🎯 Prevent Middleware Chain Execution After Writing Response - #17

Open
TaherEzzi wants to merge 1 commit into
LiliannaBruflat83:mainfrom
TaherEzzi:fix-issue-1
Open

TaherEzzi wants to merge 1 commit into
LiliannaBruflat83:mainfrom
TaherEzzi:fix-issue-1

Conversation

@TaherEzzi

Copy link
Copy Markdown

Summary

This Pull Request resolves issue #1: 🎯 Prevent Middleware Chain Execution After Writing Response / Calling http.Error.

Root Cause & Changes

To address the middleware chain execution issue after writing responses, the following files have been modified by adding return statements after calls to http.Error, w.Write, or w.WriteHeader to halt further processing.

package main

import (
	"net/http"
)

func AuthMiddleware(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		token := r.Header.Get("Authorization")
		if token == "" {
			http.Error(w, "U

### Files Modified

middleware/auth.go | 16 ++++++++++++++++
middleware/cors.go | 17 +++++++++++++++++
2 files changed, 33 insertions(+)


### Verification
- Tested with regression unit tests.
- Code conforms to standard project lint/formatting.

Closes #1
Fixes #1
/claim

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.

1 participant