修复HttpClient5Response无响应体导致的空指针问题(issue#3930@Github)

This commit is contained in:
Looly
2025-05-07 10:41:58 +08:00
parent 1a102f9359
commit 50d9182b97
2 changed files with 10 additions and 7 deletions

View File

@@ -96,7 +96,7 @@ public class HttpClient5Response extends SimpleWrapper<ClassicHttpResponse> impl
@Override
public long contentLength() {
return this.entity.getContentLength();
return null == this.entity ? -1 : this.entity.getContentLength();
}
@Override
@@ -106,6 +106,9 @@ public class HttpClient5Response extends SimpleWrapper<ClassicHttpResponse> impl
@Override
public InputStream bodyStream() {
if(null == this.entity){
return null;
}
try {
return this.entity.getContent();
} catch (final IOException e) {
@@ -130,6 +133,9 @@ public class HttpClient5Response extends SimpleWrapper<ClassicHttpResponse> impl
@Override
public String bodyStr() throws HttpException {
if(null == this.entity){
return null;
}
try {
return EntityUtils.toString(this.entity, charset());
} catch (final IOException e) {