7
7
import java .util .Optional ;
8
8
9
9
import org .apache .commons .io .IOUtils ;
10
+ import org .apache .http .HttpEntity ;
10
11
import org .apache .http .HttpResponse ;
11
12
import org .apache .http .client .methods .CloseableHttpResponse ;
12
13
import org .apache .http .impl .client .CloseableHttpClient ;
@@ -85,13 +86,13 @@ public Page download(Request request, Task task) {
85
86
page = handleResponse (request , request .getCharset () != null ? request .getCharset () : task .getSite ().getCharset (), httpResponse , task );
86
87
87
88
onSuccess (page , task );
88
- logger .info ("downloading page success {}" , request .getUrl ());
89
+ logger .info ("Download page success: {}" , request .getUrl ());
89
90
90
91
return page ;
91
92
} catch (IOException e ) {
92
93
93
94
onError (page , task , e );
94
- logger .info ("download page {} error " , request .getUrl (), e );
95
+ logger .info ("Download page error: {} " , request .getUrl (), e );
95
96
96
97
return page ;
97
98
} finally {
@@ -111,7 +112,8 @@ public void setThread(int thread) {
111
112
}
112
113
113
114
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 ];;
115
117
String contentType = httpResponse .getEntity ().getContentType () == null ? "" : httpResponse .getEntity ().getContentType ().getValue ();
116
118
Page page = new Page ();
117
119
page .setBytes (bytes );
0 commit comments