18
18
19
19
package com .loopj .android .http ;
20
20
21
+ import android .util .Log ;
22
+
21
23
import org .apache .http .Header ;
22
24
import org .apache .http .HttpResponse ;
23
25
import org .apache .http .StatusLine ;
24
26
import org .apache .http .client .HttpResponseException ;
25
27
26
28
import java .io .IOException ;
27
29
import java .util .regex .Pattern ;
30
+ import java .util .regex .PatternSyntaxException ;
28
31
29
32
/**
30
33
* Used to intercept and handle the responses from requests made using
@@ -60,6 +63,8 @@ public class BinaryHttpResponseHandler extends AsyncHttpResponseHandler {
60
63
/**
61
64
* Method can be overriden to return allowed content types,
62
65
* can be sometimes better than passing data in constructor
66
+ *
67
+ * @return array of content-types or Pattern string templates (eg. '.*' to match every response)
63
68
*/
64
69
public String [] getAllowedContentTypes () {
65
70
return mAllowedContentTypes ;
@@ -76,7 +81,7 @@ public BinaryHttpResponseHandler() {
76
81
* Creates a new BinaryHttpResponseHandler, and overrides the default allowed
77
82
* content types with passed String array (hopefully) of content types.
78
83
*
79
- * @param allowedContentTypes content types array, eg. 'image/jpeg'
84
+ * @param allowedContentTypes content types array, eg. 'image/jpeg' or pattern '.*'
80
85
*/
81
86
public BinaryHttpResponseHandler (String [] allowedContentTypes ) {
82
87
this ();
@@ -150,8 +155,12 @@ protected void sendResponseMessage(HttpResponse response) throws IOException {
150
155
Header contentTypeHeader = contentTypeHeaders [0 ];
151
156
boolean foundAllowedContentType = false ;
152
157
for (String anAllowedContentType : getAllowedContentTypes ()) {
153
- if (Pattern .matches (anAllowedContentType , contentTypeHeader .getValue ())) {
154
- foundAllowedContentType = true ;
158
+ try {
159
+ if (Pattern .matches (anAllowedContentType , contentTypeHeader .getValue ())) {
160
+ foundAllowedContentType = true ;
161
+ }
162
+ } catch (PatternSyntaxException e ) {
163
+ Log .e ("BinaryHttpResponseHandler" , "Given pattern is not valid: " + anAllowedContentType , e );
155
164
}
156
165
}
157
166
if (!foundAllowedContentType ) {
0 commit comments