# RuntimeError: Cannot modify headers; the response has already started.

- **ID:** `python/starlette-immutable-headers`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Middleware attempts to set response headers after the response body has begun streaming.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (92% success)
   ```
   response = await call_next(request)
response.headers['X-Custom'] = 'v'
return response
   ```
2. **** (85% success)
   ```
   class H(Response):
    def __init__(self, *a, **k):
        super().__init__(*a, **k)
        self.headers['X-Custom'] = 'v'
   ```

## Dead Ends

- **** — Headers are already sent before the generator runs. (90% fail)
- **** — The intended header is silently dropped. (80% fail)
