http: superfluous response.WriteHeader call Go Origin: Application & API Last updated 4 Nov 2026

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.

Exact message you may see http: superfluous response.WriteHeader callhttp: superfluous response.WriteHeader call from main.handlersuperfluous response.WriteHeader call from
Seen on: Go

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

  1. return immediately after http.Error(...)
  2. Call w.WriteHeader(code) before any w.Write
  3. Avoid writing from middleware after the handler

Detailed fix by platform

Go

  1. if err != nil { http.Error(w, err.Error(), 500); return }

How to diagnose

  1. Order — Header before body?
  2. Return — After errors?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

assignment mismatch: 1 variable but f returns 2 values — Go: assignment mismatch: 1 variable but os.Open returns 2 values (Go)assignment mismatch: …cannot assign to struct field m[k].f in map — Go: cannot assign to struct field users["bob"].Age in map (Go)cannot assign to stru…Client.Timeout exceeded while awaiting headers — Go: net/http: request canceled (Client.Timeout exceeded while awaiting headers) (Go)Client.Timeout exceed…dial tcp: connect: connection refused — Go: dial tcp 127.0.0.1:5432: connect: connection refused (Go)dial tcp: connect: co…invalid character looking for beginning of value — Go: invalid character '<' looking for beginning of value (Go)invalid character loo…listen tcp :8080: bind: address already in use — Go: listen tcp :8080: bind: address already in use (Go)listen tcp :8080: bin…panic: assignment to entry in nil map — Go: panic: assignment to entry in nil map (Go)panic: assignment to …http: sup…

Explore the map of this error Full error map →

🧠 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.