17
17
18
18
import java .io .IOException ;
19
19
20
+ import org .apache .http .Header ;
20
21
import org .apache .http .HttpEntity ;
21
22
import org .apache .http .HttpException ;
22
23
import org .apache .http .HttpResponse ;
@@ -52,9 +53,7 @@ public ResponseConsumerDelegate(final Observer<? super ObservableHttpResponse> o
52
53
@ Override
53
54
protected void onResponseReceived (HttpResponse response ) throws HttpException , IOException {
54
55
// 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 )) {
58
57
consumer = new ResponseConsumerEventStream (observer , subscription );
59
58
} else {
60
59
consumer = new ResponseConsumerBasic (observer , subscription );
@@ -63,6 +62,20 @@ protected void onResponseReceived(HttpResponse response) throws HttpException, I
63
62
consumer ._onResponseReceived (response );
64
63
}
65
64
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
+
66
79
@ Override
67
80
protected void onContentReceived (ContentDecoder decoder , IOControl ioctrl ) throws IOException {
68
81
consumer ._onContentReceived (decoder , ioctrl );
0 commit comments