Merge branch 'master' of github.com:itinance/react-native-fs

* 'master' of github.com:itinance/react-native-fs:
  Handle 307/308 redirect
  set response statuscode even if content length is zero
  Update Downloader.m
  Update Downloader.m
This commit is contained in:
Hagen Hübel 2017-04-28 02:32:11 +02:00
commit 6539499c84
2 changed files with 10 additions and 2 deletions

View File

@ -88,6 +88,10 @@
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{ {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)downloadTask.response;
if (!_statusCode) {
_statusCode = [NSNumber numberWithLong:httpResponse.statusCode];
}
NSURL *destURL = [NSURL fileURLWithPath:_params.toFile]; NSURL *destURL = [NSURL fileURLWithPath:_params.toFile];
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = nil; NSError *error = nil;
@ -102,7 +106,9 @@
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
{ {
return error ? _params.errorCallback(error) : nil; if (error && error.code != -999) {
_params.errorCallback(error);
}
} }
- (void)stopDownload - (void)stopDownload

View File

@ -67,7 +67,9 @@ public class Downloader extends AsyncTask<DownloadParams, int[], DownloadResult>
statusCode != HttpURLConnection.HTTP_OK && statusCode != HttpURLConnection.HTTP_OK &&
( (
statusCode == HttpURLConnection.HTTP_MOVED_PERM || statusCode == HttpURLConnection.HTTP_MOVED_PERM ||
statusCode == HttpURLConnection.HTTP_MOVED_TEMP statusCode == HttpURLConnection.HTTP_MOVED_TEMP ||
statusCode == 307 ||
statusCode == 308
) )
); );