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

Commit

Permalink
Change #29 IOS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Jun 21, 2016
1 parent e2515cc commit 9ecee65
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/ios/RNFetchBlob/RNFetchBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ - (NSDictionary *)constantsToExport
if([body hasPrefix:self.filePathPrefix]) {
NSString * orgPath = [body substringFromIndex:[self.filePathPrefix length]];
[request setHTTPBodyStream: [NSInputStream inputStreamWithFileAtPath:orgPath ]];
// blobData = [[NSData alloc] initWithContentsOfFile:orgPath];
}
// otherwise convert it as BASE64 data string
else {
Expand Down
19 changes: 14 additions & 5 deletions src/ios/RNFetchBlobNetwork.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu

NSString * path = [self.options valueForKey:CONFIG_FILE_PATH];
NSString * ext = [self.options valueForKey:CONFIG_FILE_EXT];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession * session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
NSURLSession * session;

// NSURLSession * session = [NSURLSession sharedSession];
// the session trust any SSL certification
if([options valueForKey:CONFIG_TRUSTY] != nil)
{
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
}
// the session validates SSL certification, self-signed certification will be aborted
else
{
session = [NSURLSession sharedSession];
}

// file will be stored at a specific path
if( path != nil) {
Expand Down Expand Up @@ -210,10 +219,10 @@ - (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)sessio

- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
if([options valueForKey:CONFIG_TRUSTY] == YES)
if([options valueForKey:CONFIG_TRUSTY] != nil)
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
else
RCTLogError(@"counld not create connection with an unstrusted SSL certification, if you're going to create connection anyway, add `trusty:true` to RNFetchBlob.config");
RCTLogWarn(@"counld not create connection with an unstrusted SSL certification, if you're going to create connection anyway, add `trusty:true` to RNFetchBlob.config");
}

@end
13 changes: 0 additions & 13 deletions test/test-0.1.x-0.4.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,3 @@ describe('Progress report test', (report, done) => {
})

})

// FIXME : not yet supported
// describe('Large file download test', (report, done) => {
// let received = 0
// RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`, {
// Authorization : 'Bearer abde123eqweje'
// })
// .then((resp) => {
// report(<Assert key="not supported" expect={true} actual={false}/>)
// done()
// })

// })
87 changes: 87 additions & 0 deletions test/test-0.5.3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import RNTest from './react-native-testkit/'
import React from 'react'
import RNFetchBlob from 'react-native-fetch-blob'

import {
StyleSheet,
Text,
View,
ScrollView,
Platform,
Dimensions,
Image,
} from 'react-native';

const fs = RNFetchBlob.fs
const { Assert, Comparer, Info, prop } = RNTest
const describe = RNTest.config({
group : '0.5.3',
run : true,
expand : false,
})
const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()

let prefix = ((Platform.OS === 'android') ? 'file://' : '')


describe('GET request with params', (report, done) => {
let time = Date.now()
RNFetchBlob
.config({ fileCache : true, trusty : true })
.fetch('GET', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
.then((resp) => {
let file = resp.path()
return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
})
.then((stream) => {
let result = ''
stream.open()
stream.onData((chunk) => {
result += chunk
})
stream.onEnd(() => {
result = JSON.parse(result)
report(<Assert key="param#1 should correct"
expect={parseInt(time)}
actual={parseInt(result.time)}/>,
<Assert key="param#2 should correct"
expect={'RNFetchBlobParams'}
actual={result.name}/>,
<Assert key="param contains unicode data should correct"
expect={'中文'}
actual={result.lang}/>)
done()
})
})
})


describe('POST request with params', (report, done) => {
let time = Date.now()
RNFetchBlob.config({ fileCache : true, trusty : true })
.fetch('POST', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
.then((resp) => {
let file = resp.path()
return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
})
.then((stream) => {
let result = ''
stream.open()
stream.onData((chunk) => {
result += chunk
})
stream.onEnd(() => {
result = JSON.parse(result)
report(<Assert key="param#1 should correct"
expect={parseInt(time)}
actual={parseInt(result.time)}/>,
<Assert key="param#2 should correct"
expect={'RNFetchBlobParams'}
actual={result.name}/>,
<Assert key="param contains unicode data should correct"
expect={'中文'}
actual={result.lang}/>)
done()
})
})
})
11 changes: 6 additions & 5 deletions test/test-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ describe('GET image from server', (report, done) => {
})
})

// require('./test-0.1.x-0.4.x')
// require('./test-0.5.1')
// require('./test-0.5.2')
// require('./test-fs')
require('./test-android')
require('./test-0.1.x-0.4.x')
require('./test-0.5.1')
require('./test-0.5.2')
require('./test-0.5.3')
require('./test-fs')
// require('./test-android')

0 comments on commit 9ecee65

Please sign in to comment.