Skip to content

Commit 90e6b4a

Browse files
committed
Fix content type encoding suffix stripping issue wkh237#293
1 parent f451a2c commit 90e6b4a

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ else if (value.equalsIgnoreCase("utf8"))
220220
responseFormat = ResponseFormat.UTF8;
221221
}
222222
else {
223-
builder.header(key, value);
224-
mheaders.put(key, value);
223+
builder.header(key.toLowerCase(), value);
224+
mheaders.put(key.toLowerCase(), value);
225225
}
226226
}
227227
}
@@ -304,9 +304,9 @@ else if(cType.isEmpty()) {
304304
clientBuilder.addNetworkInterceptor(new Interceptor() {
305305
@Override
306306
public Response intercept(Chain chain) throws IOException {
307-
redirects.add(chain.request().url().toString());
308-
return chain.proceed(chain.request());
309-
}
307+
redirects.add(chain.request().url().toString());
308+
return chain.proceed(chain.request());
309+
}
310310
});
311311
// Add request interceptor for upload progress event
312312
clientBuilder.addInterceptor(new Interceptor() {
@@ -500,32 +500,11 @@ private void done(Response resp) {
500500
// It uses customized response body which is able to report download progress
501501
// and write response data to destination path.
502502
resp.body().bytes();
503-
504503
} catch (Exception ignored) {
505504
// ignored.printStackTrace();
506505
}
507506
this.destPath = this.destPath.replace("?append=true", "");
508-
509-
try {
510-
long expectedLength = resp.body().contentLength();
511-
// when response contains Content-Length, check if the stream length is correct
512-
if(expectedLength > 0) {
513-
long actualLength = new File(this.destPath).length();
514-
if(actualLength != expectedLength) {
515-
callback.invoke("RNFetchBlob failed to write data to storage : expected " + expectedLength + " bytes but got " + actualLength + " bytes", null);
516-
}
517-
else {
518-
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
519-
}
520-
}
521-
else {
522-
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
523-
}
524-
}
525-
catch (Exception err) {
526-
callback.invoke(err.getMessage());
527-
err.printStackTrace();
528-
}
507+
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
529508
break;
530509
default:
531510
try {
@@ -536,7 +515,7 @@ private void done(Response resp) {
536515
break;
537516
}
538517
// if(!resp.isSuccessful())
539-
resp.body().close();
518+
resp.body().close();
540519
releaseTaskResource();
541520
}
542521

@@ -578,7 +557,7 @@ private WritableMap getResponseInfo(Response resp, boolean isBlobResp) {
578557
}
579558
WritableArray redirectList = Arguments.createArray();
580559
for(String r : redirects) {
581-
redirectList.pushString(r);
560+
redirectList.pushString(r);
582561
}
583562
info.putArray("redirects", redirectList);
584563
info.putMap("headers", headers);
@@ -629,7 +608,8 @@ private String getHeaderIgnoreCases(Headers headers, String field) {
629608
private String getHeaderIgnoreCases(HashMap<String,String> headers, String field) {
630609
String val = headers.get(field);
631610
if(val != null) return val;
632-
return headers.get(field.toLowerCase()) == null ? "" : headers.get(field.toLowerCase());
611+
String lowerCasedValue = headers.get(field.toLowerCase());
612+
return lowerCasedValue == null ? "" : lowerCasedValue;
633613
}
634614

635615
private void emitStateEvent(WritableMap args) {

0 commit comments

Comments
 (0)