Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit a7dab12

Browse files
committed
Add new propertyredirects to class RNFetchBlobResp #111
1 parent 4be60dc commit a7dab12

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.facebook.react.bridge.ReadableArray;
1818
import com.facebook.react.bridge.ReadableMap;
1919
import com.facebook.react.bridge.ReadableMapKeySetIterator;
20+
import com.facebook.react.bridge.WritableArray;
2021
import com.facebook.react.bridge.WritableMap;
2122
import com.facebook.react.modules.core.DeviceEventManagerModule;
2223

@@ -32,6 +33,7 @@
3233
import java.nio.charset.CharacterCodingException;
3334
import java.nio.charset.Charset;
3435
import java.nio.charset.CharsetEncoder;
36+
import java.util.ArrayList;
3537
import java.util.HashMap;
3638
import java.util.concurrent.TimeUnit;
3739

@@ -72,6 +74,7 @@ enum ResponseType {
7274

7375
ReactApplicationContext ctx;
7476
RNFetchBlobConfig options;
77+
ArrayList<String> redirects = new ArrayList<>();
7578
String taskId;
7679
String method;
7780
String url;
@@ -280,6 +283,14 @@ else if(cType.isEmpty()) {
280283

281284
final Request req = builder.build();
282285

286+
clientBuilder.addNetworkInterceptor(new Interceptor() {
287+
@Override
288+
public Response intercept(Chain chain) throws IOException {
289+
redirects.add(chain.request().url().toString());
290+
return chain.proceed(chain.request());
291+
}
292+
});
293+
283294
// Add request interceptor for upload progress event
284295
clientBuilder.addInterceptor(new Interceptor() {
285296
@Override
@@ -509,6 +520,11 @@ private WritableMap getResponseInfo(Response resp, boolean isBlobResp) {
509520
headers.putString(resp.headers().name(i), resp.headers().value(i));
510521
}
511522
info.putMap("headers", headers);
523+
WritableArray redirectList = Arguments.createArray();
524+
for(String r : redirects) {
525+
redirectList.pushString(r);
526+
}
527+
info.putArray("redirects", redirectList);
512528
Headers h = resp.headers();
513529
if(isBlobResp) {
514530
info.putString("respType", "blob");

src/ios/RNFetchBlobNetwork.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ @interface RNFetchBlobNetwork ()
3636
long bodyLength;
3737
NSMutableDictionary * respInfo;
3838
NSInteger respStatus;
39+
NSMutableArray * redirects;
3940
}
4041

4142
@end
@@ -125,6 +126,8 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
125126
self.expectedBytes = 0;
126127
self.receivedBytes = 0;
127128
self.options = options;
129+
redirects = [[NSMutableArray alloc] init];
130+
[redirects addObject:req.URL.absoluteString];
128131

129132
NSString * path = [self.options valueForKey:CONFIG_FILE_PATH];
130133
NSString * ext = [self.options valueForKey:CONFIG_FILE_EXT];
@@ -242,6 +245,7 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
242245
@"taskId": taskId,
243246
@"state": @"2",
244247
@"headers": headers,
248+
@"redirects": redirects,
245249
@"respType" : respType,
246250
@"timeout" : @NO,
247251
@"status": [NSString stringWithFormat:@"%d", statusCode ]
@@ -440,5 +444,10 @@ - (void) URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthentica
440444
}
441445
}
442446

447+
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler
448+
{
449+
[redirects addObject:[request.URL absoluteString]];
450+
completionHandler(request);
451+
}
443452

444453
@end

0 commit comments

Comments
 (0)