# http: superfluous response.WriteHeader call from main.handler (server.go:42)

- **ID:** `go/http-superfluous-writeheader`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

WriteHeader is called more than once, or Write is called before WriteHeader. Only the first status code is sent.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   if !wroteHeader { w.WriteHeader(http.StatusOK); wroteHeader = true }
json.NewEncoder(w).Encode(v)
   ```
2. **** (88% success)
   ```
   Return early after writing an error status; never write body after WriteHeader without checking.
   ```

## Dead Ends

- **** — Hides a real bug; the wrong status code may be sent to clients. (80% fail)
- **** — Does not fix the underlying control flow. (70% fail)
