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

Commit ac04689

Browse files
committed
Merge branch '0.10.3'
2 parents d2b788c + 636ed98 commit ac04689

File tree

786 files changed

+275
-55234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

786 files changed

+275
-55234
lines changed

LICENSE

-21
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java renamed to android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.facebook.react.bridge.ReadableArray;
1414
import com.facebook.react.bridge.ReadableMap;
1515
import com.facebook.react.bridge.WritableArray;
16+
import com.facebook.react.bridge.WritableMap;
1617

1718
import java.util.Map;
1819
import java.util.concurrent.LinkedBlockingQueue;
@@ -230,17 +231,32 @@ public void run() {
230231
@ReactMethod
231232
/**
232233
* Get cookies belongs specific host.
233-
* @param host String host name.
234+
* @param host String domain name.
234235
*/
235-
public void getCookies(String host, Promise promise) {
236+
public void getCookies(String domain, Promise promise) {
236237
try {
237-
WritableArray cookies = RNFBCookieJar.getCookies(host);
238+
WritableMap cookies = RNFBCookieJar.getCookies(domain);
238239
promise.resolve(cookies);
239240
} catch(Exception err) {
240241
promise.reject("RNFetchBlob.getCookies", err.getMessage());
241242
}
242243
}
243244

245+
@ReactMethod
246+
/**
247+
* Remove cookies for specific domain
248+
* @param domain String of the domain
249+
* @param promise JSC promise injected by RN
250+
*/
251+
public void removeCookies(String domain, Promise promise) {
252+
try {
253+
RNFBCookieJar.removeCookies(domain);
254+
promise.resolve(null);
255+
} catch(Exception err) {
256+
promise.reject("RNFetchBlob.removeCookies", err.getMessage());
257+
}
258+
}
259+
244260
@ReactMethod
245261
/**
246262
* @param path Stream file path

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java renamed to android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ public void readStream(String path, String encoding, int bufferSize, int tick, f
248248
CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
249249
while ((cursor = fs.read(buffer)) != -1) {
250250
encoder.encode(ByteBuffer.wrap(buffer).asCharBuffer());
251-
// if the data contains invalid characters the following lines will be
252-
// skipped.
253251
String chunk = new String(buffer);
252+
if(cursor != bufferSize)
253+
chunk = chunk.substring(0, cursor);
254254
emitStreamEvent(streamId, "data", chunk);
255255
if(tick > 0)
256256
SystemClock.sleep(tick);

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,32 @@ 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+
503504
} catch (Exception ignored) {
504505
// ignored.printStackTrace();
505506
}
506507
this.destPath = this.destPath.replace("?append=true", "");
507-
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
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+
}
508529
break;
509530
default:
510531
try {

src/android/src/main/java/com/RNFetchBlob/Utils/RNFBCookieJar.java renamed to android/src/main/java/com/RNFetchBlob/Utils/RNFBCookieJar.java

+24-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.ArrayList;
99
import java.util.HashMap;
1010
import java.util.List;
11+
import java.util.Set;
1112

1213
import okhttp3.Cookie;
1314
import okhttp3.CookieJar;
@@ -35,19 +36,31 @@ public List<Cookie> loadForRequest(HttpUrl url) {
3536
return cookies != null ? cookies : new ArrayList<Cookie>();
3637
}
3738

38-
public static WritableArray getCookies(String host) {
39-
HttpUrl url = HttpUrl.parse(host);
40-
List<Cookie> cookies = null;
41-
if(url != null) {
42-
cookies = cookieStore.get(url.host());
39+
public static void removeCookies(String domain) {
40+
if(domain != null && domain.length() > 0) {
41+
if(cookieStore.containsKey(domain))
42+
cookieStore.remove(domain);
4343
}
44-
WritableArray cookieList = Arguments.createArray();
45-
if(cookies != null) {
46-
for(Cookie c : cookies){
47-
cookieList.pushString(c.toString());
44+
else
45+
cookieStore.clear();
46+
}
47+
48+
public static WritableMap getCookies(String host) {
49+
Set<String> domains = cookieStore.keySet();
50+
WritableMap cookieMap = Arguments.createMap();
51+
if(host.length() > 0 && cookieStore.containsKey(host)) {
52+
domains.clear();
53+
domains.add(host);
54+
}
55+
// no domain specified, return all cookies
56+
for(String key : domains) {
57+
WritableArray cookiesInDomain = Arguments.createArray();
58+
for(Cookie c: cookieStore.get(key)){
59+
cookiesInDomain.pushString(c.toString());
4860
}
49-
return cookieList;
61+
cookieMap.putArray(key, cookiesInDomain);
5062
}
51-
return null;
63+
64+
return cookieMap;
5265
}
5366
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/fs.js renamed to fs.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ function stat(path:string):Promise<RNFetchBlobFile> {
201201
if(err)
202202
reject(new Error(err))
203203
else {
204-
if(stat)
204+
if(stat) {
205+
stat.size = parseInt(stat.size)
205206
stat.lastModified = parseInt(stat.lastModified)
207+
}
206208
resolve(stat)
207209
}
208210
})

img/RNFB-HTTP-flow.png

-70.9 KB
Binary file not shown.

img/RNFB-flow (1).png

-56.4 KB
Binary file not shown.

img/RNFB-flow.png

-58.3 KB
Binary file not shown.

img/action-menu.png

-69.5 KB
Binary file not shown.

img/android-notification1.png

-22.2 KB
Binary file not shown.

img/android-notification2.png

-7.17 KB
Binary file not shown.

img/download-manager.png

-22.6 KB
Binary file not shown.

img/ios-1.png

-203 KB
Binary file not shown.

img/ios-2.png

-256 KB
Binary file not shown.

img/ios-3.png

-160 KB
Binary file not shown.

img/ios-4.png

-83.4 KB
Binary file not shown.

img/ios-5.png

-148 KB
Binary file not shown.

img/issue_57_1.png

-204 KB
Binary file not shown.

img/issue_57_2.png

-207 KB
Binary file not shown.

img/issue_57_3.png

-230 KB
Binary file not shown.

img/performance_1.png

-81.6 KB
Binary file not shown.

img/performance_encoding.png

-100 KB
Binary file not shown.

img/performance_f2f.png

-104 KB
Binary file not shown.

src/index.js renamed to index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,12 @@ function fetch(...args:any):Promise {
247247
})
248248

249249
stateEvent = emitter.addListener('RNFetchBlobState', (e) => {
250-
respInfo = e
251-
if(e.taskId === taskId && promise.onStateChange) {
252-
promise.onStateChange(e)
253-
}
250+
if(e.taskId === taskId)
251+
respInfo = e
252+
promise.onStateChange && promise.onStateChange(e)
254253
})
255254

256255
subscription = emitter.addListener('RNFetchBlobExpire', (e) => {
257-
console.log(e , 'EXPIRED!!')
258256
if(e.taskId === taskId && promise.onExpire) {
259257
promise.onExpire(e)
260258
}

src/ios.js renamed to ios.js

File renamed without changes.
File renamed without changes.
File renamed without changes.

src/ios/RNFetchBlob/RNFetchBlob.m renamed to ios/RNFetchBlob/RNFetchBlob.m

+15
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,24 @@ - (UIViewController *) documentInteractionControllerViewControllerForPreview: (U
519519
}
520520

521521
# pragma mark - getCookies
522+
522523
RCT_EXPORT_METHOD(getCookies:(NSString *)url resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
523524
{
524525
resolve([RNFetchBlobNetwork getCookies:url]);
525526
}
526527

528+
# pragma mark - removeCookie
529+
530+
RCT_EXPORT_METHOD(removeCookies:(NSString *)domain resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
531+
{
532+
NSError * err = nil;
533+
[RNFetchBlobNetwork removeCookies:domain error:&err];
534+
if(err)
535+
reject(@"RNFetchBlob failed to remove cookie", @"RNFetchBlob failed to remove cookie", nil);
536+
else
537+
resolve(@[[NSNull null]]);
538+
}
539+
527540
# pragma mark - check expired network events
528541

529542
RCT_EXPORT_METHOD(emitExpiredEvent:(RCTResponseSenderBlock)callback)
@@ -532,4 +545,6 @@ - (UIViewController *) documentInteractionControllerViewControllerForPreview: (U
532545
}
533546

534547

548+
549+
535550
@end
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/ios/RNFetchBlobFS.m renamed to ios/RNFetchBlobFS.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ + (NSDictionary *) stat:(NSString *) path error:(NSError **) error {
516516
@"size" : size,
517517
@"filename" : filename,
518518
@"path" : path,
519-
@"lastModified" : [NSNumber numberWithLong:(time_t) [lastModified timeIntervalSince1970]*1000],
519+
@"lastModified" : [NSString stringWithFormat:@"%@", [NSNumber numberWithLong:(time_t) [lastModified timeIntervalSince1970]*1000]],
520520
@"type" : isDir ? @"directory" : @"file"
521521
};
522522

src/ios/RNFetchBlobNetwork.h renamed to ios/RNFetchBlobNetwork.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323

2424
typedef void(^CompletionHander)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error);
2525
typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error);
26+
typedef NS_ENUM(NSUInteger, ResponseFormat) {
27+
UTF8,
28+
BASE64,
29+
AUTO
30+
};
2631

2732
@interface RNFetchBlobNetwork : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
2833

@@ -38,6 +43,19 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
3843
@property (strong, nonatomic) CompletionHander fileTaskCompletionHandler;
3944
@property (strong, nonatomic) DataTaskCompletionHander dataTaskCompletionHandler;
4045
@property (nullable, nonatomic) NSError * error;
46+
@property (nullable, nonatomic) NSMutableArray * redirects;
47+
48+
@property (nonatomic) BOOL respFile;
49+
@property (nonatomic) BOOL isNewPart;
50+
@property (nonatomic) BOOL isIncrement;
51+
@property (nullable, nonatomic) NSMutableData * partBuffer;
52+
@property (nullable, nonatomic) NSString * destPath;
53+
@property (nullable, nonatomic) NSOutputStream * writeStream;
54+
@property (nonatomic) long bodyLength;
55+
@property (nullable, nonatomic) NSMutableDictionary * respInfo;
56+
@property (nonatomic) NSInteger respStatus;
57+
@property (nonatomic) ResponseFormat responseFormat;
58+
@property ( nonatomic) BOOL followRedirect;
4159

4260

4361
+ (NSMutableDictionary * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
@@ -49,9 +67,10 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
4967
- (nullable id) init;
5068
- (void) sendRequest;
5169
- (void) sendRequest:(NSDictionary * _Nullable )options contentLength:(long)contentLength bridge:(RCTBridge * _Nullable)bridgeRef taskId:(NSString * _Nullable)taskId withRequest:(NSURLRequest * _Nullable)req callback:(_Nullable RCTResponseSenderBlock) callback;
70+
+ (void) removeCookies:(NSString *) domain error:(NSError **)error;
5271
+ (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)config;
5372
+ (void) enableUploadProgress:(NSString *) taskId config:(RNFetchBlobProgress *)config;
54-
+ (NSArray *) getCookies:(NSString *) url;
73+
+ (NSDictionary *) getCookies:(NSString *) url;
5574

5675

5776

0 commit comments

Comments
 (0)