# upstream sent chunked transfer encoding while sending Content-Length header, client: 10.0.0.1, server: example.com

- **ID:** `nginx/upstream-sent-http-1-1-chunked-with-content-length`
- **Domain:** nginx
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

Upstream server sends conflicting HTTP headers: both Content-Length and Transfer-Encoding: chunked, violating HTTP/1.1 spec.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx 1.20.2 | active | — | — |
| nginx 1.22.1 | active | — | — |
| nginx 1.24.0 | active | — | — |
| nginx 1.26.0 | active | — | — |

## Workarounds

1. **Fix the upstream application to not send both Content-Length and Transfer-Encoding headers. For example, in a Python Flask app, remove the Content-Length header when using chunked encoding:
@app.after_request
def remove_conflicting_headers(response):
    if response.headers.get('Transfer-Encoding') == 'chunked':
        response.headers.pop('Content-Length', None)
    return response** (85% success)
   ```
   Fix the upstream application to not send both Content-Length and Transfer-Encoding headers. For example, in a Python Flask app, remove the Content-Length header when using chunked encoding:
@app.after_request
def remove_conflicting_headers(response):
    if response.headers.get('Transfer-Encoding') == 'chunked':
        response.headers.pop('Content-Length', None)
    return response
   ```
2. **Use nginx's proxy_hide_header directive to remove the conflicting Content-Length header from upstream responses:
proxy_hide_header Content-Length;
This forces nginx to rely on chunked encoding alone.** (75% success)
   ```
   Use nginx's proxy_hide_header directive to remove the conflicting Content-Length header from upstream responses:
proxy_hide_header Content-Length;
This forces nginx to rely on chunked encoding alone.
   ```

## Dead Ends

- **Set proxy_http_version 1.0;** — HTTP/1.0 does not support chunked encoding, but the upstream may still send conflicting headers; this can cause other issues like connection close. (70% fail)
- **Disable chunked transfer with proxy_set_header Transfer-Encoding '';** — This removes the header from the request to upstream, not the response; the error is about the response from upstream. (90% fail)
- **Increase proxy_buffer_size** — Buffer size does not affect header parsing or protocol compliance; the error is a protocol violation, not a buffer overflow. (95% fail)
