Skip to content

Commit 78740a4

Browse files
committed
Fix NPE.
1 parent 5afe3e7 commit 78740a4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Optional;
88

99
import org.apache.commons.io.IOUtils;
10+
import org.apache.http.HttpEntity;
1011
import org.apache.http.HttpResponse;
1112
import org.apache.http.client.methods.CloseableHttpResponse;
1213
import org.apache.http.impl.client.CloseableHttpClient;
@@ -111,7 +112,8 @@ public void setThread(int thread) {
111112
}
112113

113114
protected Page handleResponse(Request request, String charset, HttpResponse httpResponse, Task task) throws IOException {
114-
byte[] bytes = IOUtils.toByteArray(httpResponse.getEntity().getContent());
115+
HttpEntity entity = httpResponse.getEntity();
116+
byte[] bytes = entity != null ? IOUtils.toByteArray(entity.getContent()) : new byte[0];;
115117
String contentType = httpResponse.getEntity().getContentType() == null ? "" : httpResponse.getEntity().getContentType().getValue();
116118
Page page = new Page();
117119
page.setBytes(bytes);

0 commit comments

Comments
 (0)