77import java .util .Optional ;
88
99import org .apache .commons .io .IOUtils ;
10+ import org .apache .http .HttpEntity ;
1011import org .apache .http .HttpResponse ;
1112import org .apache .http .client .methods .CloseableHttpResponse ;
1213import org .apache .http .impl .client .CloseableHttpClient ;
@@ -85,13 +86,13 @@ public Page download(Request request, Task task) {
8586 page = handleResponse (request , request .getCharset () != null ? request .getCharset () : task .getSite ().getCharset (), httpResponse , task );
8687
8788 onSuccess (page , task );
88- logger .info ("downloading page success {}" , request .getUrl ());
89+ logger .info ("Download page success: {}" , request .getUrl ());
8990
9091 return page ;
9192 } catch (IOException e ) {
9293
9394 onError (page , task , e );
94- logger .info ("download page {} error " , request .getUrl (), e );
95+ logger .info ("Download page error: {} " , request .getUrl (), e );
9596
9697 return page ;
9798 } finally {
@@ -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