Skip to content

Commit 4823d9a

Browse files
committed
Revert "HttpClient: attempt to avoid content length header parsing if we have a body content length we can use"
This reverts commit f730779. We always want to prefer the header supplied value if it's available. This logic is just simpler to understand and likely safer.
1 parent 55be2ff commit 4823d9a

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

client/src/main/java/org/threadly/litesockets/client/http/HTTPClient.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,11 @@ public HTTPResponseCode getResponseCode() {
594594
}
595595

596596
public long getContentLength() {
597-
long result = body.remaining();
598-
if (result > 0) {
599-
return result;
600-
}
601-
result = hr.getHeaders().getContentLength();
602-
if (result > 0) {
597+
long result = hr.getHeaders().getContentLength();
598+
if (result >= 0) {
603599
return result;
604600
} else {
605-
return 0;
601+
return body.remaining();
606602
}
607603
}
608604

protocol/src/main/java/org/threadly/litesockets/protocols/http/response/HTTPResponseProcessor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ public void connectionClosed() {
138138
reset(new HTTPParsingException("Did not complete chunked encoding!"));
139139
}
140140
} else {
141-
if(response.getHeaders().getContentLength() > 0 &&
142-
response.getHeaders().getContentLength() != this.currentBodySize) {
141+
if(response.getHeaders().getContentLength() > 0 && response.getHeaders().getContentLength() != this.currentBodySize) {
143142
reset(new HTTPParsingException("Did not get complete body!"));
144143
} else {
145144
reset(null);

0 commit comments

Comments
 (0)