Go: http: superfluous response.WriteHeader call from main.handler (main.go:25)
A handler wrote the status header more than once, or wrote the body first (which sends 200) and then tried to set another status.
http: superfluous response.WriteHeader callhttp: superfluous response.WriteHeader call from main.handlersuperfluous response.WriteHeader call from Meaning
The first Write implicitly sends status 200. Calling WriteHeader or http.Error afterwards is ignored and logged. Return after sending an error, and set status/headers before writing the body.
Common causes
- http.Error followed by more writes
- Missing return after writing an error response
- WriteHeader called after Write
- Middleware and handler both writing
- Calling WriteHeader twice
⚡ Quick fix
returnimmediately afterhttp.Error(...)- Call
w.WriteHeader(code)before anyw.Write - Avoid writing from middleware after the handler
Detailed fix by platform
Go
if err != nil { http.Error(w, err.Error(), 500); return }
How to diagnose
- Order — Header before body?
- Return — After errors?
- Writers — Multiple layers?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- assignment mismatch: 1 variable but f returns 2 values Go: assignment mismatch: 1 variable but os.Open returns 2 values
- cannot assign to struct field m[k].f in map Go: cannot assign to struct field users["bob"].Age in map
- Client.Timeout exceeded while awaiting headers Go: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026