cap negative Content-Length in DefaultClient response conversion · OpenFeign/feign@051d18f · GitHub
Skip to content

Commit 051d18f

Browse files
renechoikdelay
andcommitted
cap negative Content-Length in DefaultClient response conversion
`convertResponse` mapped only `-1` to `null`, so any other negative `Content-Length` reached `Response.Body#length()` unchanged. `HttpURLConnection#getContentLength()` returns the header verbatim once it fits in an `int`, and already returns `-1` when the value is unknown or above `Integer.MAX_VALUE`. Measured against a raw socket reply on JDK 17, 21 and 26: Content-Length: -5 -> getContentLength() = -5 Content-Length: -1 -> getContentLength() = -1 Content-Length: 3000000000 -> getContentLength() = -1 Widening the guard to `< 0` therefore reports a malformed value as unknown while leaving both the `-1` and the over-2GB cases untouched. This is the same defect fixed for `Http2Client` in #3431 and for `GoogleHttpClient` in the previous commit. `Client.Default` and `Client.Proxied` extend `DefaultClient`, so they inherit the fix. Covered by tests mirroring `Http2ClientContentLengthTest`. Co-authored-by: kdelay <90545043+kdelay@users.noreply.github.com>
1 parent 2bb7da7 commit 051d18f

2 files changed

Lines changed: 112 additions & 1 deletion

File tree

‎core/src/main/java/feign/DefaultClient.java‎

Lines changed: 3 additions & 1 deletion
Lines changed: 109 additions & 0 deletions

0 commit comments

Comments
 (0)