# upstream sent invalid transfer-encoding while reading response body from upstream

- **ID:** `nginx/upstream-sent-invalid-transfer-encoding`
- **Domain:** nginx
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The upstream server returns a response with a Transfer-Encoding header that is malformed or conflicting with Content-Length, causing nginx to reject the response.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx-1.24.0 | active | — | — |
| nginx-1.25.3 | active | — | — |
| nginx-1.26.0 | active | — | — |

## Workarounds

1. **Fix the upstream application to send a valid Transfer-Encoding header. For example, in a Node.js Express app, ensure you use res.end() properly to avoid conflicting headers:
app.get('/data', (req, res) => {
    res.set('Transfer-Encoding', 'chunked');
    res.write('Hello');
    res.end();
});
# Or use a library like compression for proper encoding.** (85% success)
   ```
   Fix the upstream application to send a valid Transfer-Encoding header. For example, in a Node.js Express app, ensure you use res.end() properly to avoid conflicting headers:
app.get('/data', (req, res) => {
    res.set('Transfer-Encoding', 'chunked');
    res.write('Hello');
    res.end();
});
# Or use a library like compression for proper encoding.
   ```
2. **If the upstream is a legacy server, force nginx to use HTTP/1.1 and disable buffering to work around the issue:
location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_buffering off;
    proxy_pass http://upstream;
}** (80% success)
   ```
   If the upstream is a legacy server, force nginx to use HTTP/1.1 and disable buffering to work around the issue:
location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_buffering off;
    proxy_pass http://upstream;
}
   ```

## Dead Ends

- **** — HTTP/1.0 cannot use chunked encoding; the upstream must send Content-Length instead. (60% fail)
- **** — This only affects connection persistence, not the encoding of the response body. (90% fail)
- **** — Buffer sizes affect data handling, not header validation. (95% fail)
