|  | @@ -63,6 +63,12 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
 | 
	
		
			
			| 63 | 63 |          FileStorage
 | 
	
		
			
			| 64 | 64 |      }
 | 
	
		
			
			| 65 | 65 |  
 | 
	
		
			
			|  | 66 | +    enum ResponseFormat {
 | 
	
		
			
			|  | 67 | +        Auto,
 | 
	
		
			
			|  | 68 | +        UTF8,
 | 
	
		
			
			|  | 69 | +        BASE64
 | 
	
		
			
			|  | 70 | +    }
 | 
	
		
			
			|  | 71 | +
 | 
	
		
			
			| 66 | 72 |      public static HashMap<String, Call> taskTable = new HashMap<>();
 | 
	
		
			
			| 67 | 73 |      static HashMap<String, Boolean> progressReport = new HashMap<>();
 | 
	
		
			
			| 68 | 74 |      static HashMap<String, Boolean> uploadProgressReport = new HashMap<>();
 | 
	
	
		
			
			|  | @@ -83,8 +89,10 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
 | 
	
		
			
			| 83 | 89 |      RNFetchBlobBody requestBody;
 | 
	
		
			
			| 84 | 90 |      RequestType requestType;
 | 
	
		
			
			| 85 | 91 |      ResponseType responseType;
 | 
	
		
			
			|  | 92 | +    ResponseFormat responseFormat = ResponseFormat.Auto;
 | 
	
		
			
			| 86 | 93 |      WritableMap respInfo;
 | 
	
		
			
			| 87 | 94 |      boolean timeout = false;
 | 
	
		
			
			|  | 95 | +
 | 
	
		
			
			| 88 | 96 |      ArrayList<String> redirects = new ArrayList<>();
 | 
	
		
			
			| 89 | 97 |  
 | 
	
		
			
			| 90 | 98 |      public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, final Callback callback) {
 | 
	
	
		
			
			|  | @@ -200,8 +208,16 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
 | 
	
		
			
			| 200 | 208 |                  while (it.hasNextKey()) {
 | 
	
		
			
			| 201 | 209 |                      String key = it.nextKey();
 | 
	
		
			
			| 202 | 210 |                      String value = headers.getString(key);
 | 
	
		
			
			| 203 |  | -                    builder.header(key, value);
 | 
	
		
			
			| 204 |  | -                    mheaders.put(key,value);
 | 
	
		
			
			|  | 211 | +                    if(key.equalsIgnoreCase("RNFB-Response")) {
 | 
	
		
			
			|  | 212 | +                        if(value.equalsIgnoreCase("base64"))
 | 
	
		
			
			|  | 213 | +                            responseFormat = ResponseFormat.BASE64;
 | 
	
		
			
			|  | 214 | +                        else if (value.equalsIgnoreCase("utf8"))
 | 
	
		
			
			|  | 215 | +                            responseFormat = ResponseFormat.UTF8;
 | 
	
		
			
			|  | 216 | +                    }
 | 
	
		
			
			|  | 217 | +                    else {
 | 
	
		
			
			|  | 218 | +                        builder.header(key, value);
 | 
	
		
			
			|  | 219 | +                        mheaders.put(key, value);
 | 
	
		
			
			|  | 220 | +                    }
 | 
	
		
			
			| 205 | 221 |                  }
 | 
	
		
			
			| 206 | 222 |              }
 | 
	
		
			
			| 207 | 223 |  
 | 
	
	
		
			
			|  | @@ -439,6 +455,10 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
 | 
	
		
			
			| 439 | 455 |                          // string correctly, we should do URL encoding before BASE64.
 | 
	
		
			
			| 440 | 456 |                          byte[] b = resp.body().bytes();
 | 
	
		
			
			| 441 | 457 |                          CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
 | 
	
		
			
			|  | 458 | +                        if(responseFormat == ResponseFormat.BASE64) {
 | 
	
		
			
			|  | 459 | +                            callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
 | 
	
		
			
			|  | 460 | +                            return;
 | 
	
		
			
			|  | 461 | +                        }
 | 
	
		
			
			| 442 | 462 |                          try {
 | 
	
		
			
			| 443 | 463 |                              encoder.encode(ByteBuffer.wrap(b).asCharBuffer());
 | 
	
		
			
			| 444 | 464 |                              // if the data contains invalid characters the following lines will be
 | 
	
	
		
			
			|  | @@ -449,7 +469,12 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
 | 
	
		
			
			| 449 | 469 |                          // This usually mean the data is contains invalid unicode characters, it's
 | 
	
		
			
			| 450 | 470 |                          // binary data
 | 
	
		
			
			| 451 | 471 |                          catch(CharacterCodingException ignored) {
 | 
	
		
			
			| 452 |  | -                            callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
 | 
	
		
			
			|  | 472 | +                            if(responseFormat == ResponseFormat.UTF8) {
 | 
	
		
			
			|  | 473 | +                                callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, "");
 | 
	
		
			
			|  | 474 | +                            }
 | 
	
		
			
			|  | 475 | +                            else {
 | 
	
		
			
			|  | 476 | +                                callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
 | 
	
		
			
			|  | 477 | +                            }
 | 
	
		
			
			| 453 | 478 |                          }
 | 
	
		
			
			| 454 | 479 |                      }
 | 
	
		
			
			| 455 | 480 |                  } catch (IOException e) {
 |