1717
1818import java .io .IOException ;
1919
20+ import org .apache .http .Header ;
2021import org .apache .http .HttpEntity ;
2122import org .apache .http .HttpException ;
2223import org .apache .http .HttpResponse ;
@@ -52,9 +53,7 @@ public ResponseConsumerDelegate(final Observer<? super ObservableHttpResponse> o
5253 @ Override
5354 protected void onResponseReceived (HttpResponse response ) throws HttpException , IOException {
5455 // when we receive the response with headers we evaluate what type of consumer we want
55- if (response .getFirstHeader ("Content-Type" ).getValue ().contains ("text/event-stream" )) {
56- // use 'contains' instead of equals since Content-Type can contain additional information
57- // such as charset ... see here: http://www.w3.org/International/O-HTTP-charset
56+ if (responseIsStreamLike (response )) {
5857 consumer = new ResponseConsumerEventStream (observer , subscription );
5958 } else {
6059 consumer = new ResponseConsumerBasic (observer , subscription );
@@ -63,6 +62,20 @@ protected void onResponseReceived(HttpResponse response) throws HttpException, I
6362 consumer ._onResponseReceived (response );
6463 }
6564
65+ private boolean responseIsStreamLike (HttpResponse response ) {
66+ final Header contentType = response .getFirstHeader ("Content-Type" );
67+ // use 'contains' instead of equals since Content-Type can contain additional information
68+ // such as charset ... see here: http://www.w3.org/International/O-HTTP-charset
69+ if (contentType != null && contentType .getValue ().contains ("text/event-stream" )) {
70+ return true ;
71+ }
72+ final Header transferEncoding = response .getFirstHeader ("Transfer-Encoding" );
73+ if (transferEncoding != null && transferEncoding .getValue ().equals ("chunked" )) {
74+ return true ;
75+ }
76+ return false ;
77+ }
78+
6679 @ Override
6780 protected void onContentReceived (ContentDecoder decoder , IOControl ioctrl ) throws IOException {
6881 consumer ._onContentReceived (decoder , ioctrl );
0 commit comments