@@ -346,7 +346,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
346
346
resizeMode : (RCTResizeMode)resizeMode
347
347
progressBlock : (RCTImageLoaderProgressBlock)progressHandler
348
348
partialLoadBlock : (RCTImageLoaderPartialLoadBlock)partialLoadHandler
349
- completionBlock : (void (^)(NSError *error, id imageOrData, BOOL cacheResult, NSString *fetchDate, NSString *cacheControl ))completionBlock
349
+ completionBlock : (void (^)(NSError *error, id imageOrData, BOOL cacheResult, NSURLResponse *response ))completionBlock
350
350
{
351
351
{
352
352
NSMutableURLRequest *mutableRequest = [request mutableCopy ];
@@ -375,7 +375,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
375
375
__block atomic_bool cancelled = ATOMIC_VAR_INIT (NO );
376
376
// TODO: Protect this variable shared between threads.
377
377
__block dispatch_block_t cancelLoad = nil ;
378
- void (^completionHandler)(NSError *, id , NSString *, NSString * ) = ^(NSError *error, id imageOrData, NSString *fetchDate, NSString *cacheControl ) {
378
+ void (^completionHandler)(NSError *, id , NSURLResponse * ) = ^(NSError *error, id imageOrData, NSURLResponse *response ) {
379
379
cancelLoad = nil ;
380
380
381
381
// If we've received an image, we should try to set it synchronously,
@@ -385,11 +385,11 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
385
385
// expecting it, and may do expensive post-processing in the callback
386
386
dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
387
387
if (!atomic_load (&cancelled)) {
388
- completionBlock (error, imageOrData, cacheResult, fetchDate, cacheControl );
388
+ completionBlock (error, imageOrData, cacheResult, response );
389
389
}
390
390
});
391
391
} else if (!atomic_load (&cancelled)) {
392
- completionBlock (error, imageOrData, cacheResult, fetchDate, cacheControl );
392
+ completionBlock (error, imageOrData, cacheResult, response );
393
393
}
394
394
};
395
395
@@ -403,7 +403,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
403
403
progressHandler: progressHandler
404
404
partialLoadHandler: partialLoadHandler
405
405
completionHandler: ^(NSError *error, UIImage *image){
406
- completionHandler (error, image, nil , nil );
406
+ completionHandler (error, image, nil );
407
407
}];
408
408
}
409
409
@@ -427,7 +427,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
427
427
progressHandler: progressHandler
428
428
partialLoadHandler: partialLoadHandler
429
429
completionHandler: ^(NSError *error, UIImage *image) {
430
- completionHandler (error, image, nil , nil );
430
+ completionHandler (error, image, nil );
431
431
}];
432
432
} else {
433
433
UIImage *image;
@@ -439,7 +439,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
439
439
}
440
440
441
441
if (image) {
442
- completionHandler (nil , image, nil , nil );
442
+ completionHandler (nil , image, nil );
443
443
} else {
444
444
// Use networking module to load image
445
445
cancelLoad = [strongSelf _loadURLRequest: request
@@ -464,7 +464,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
464
464
465
465
- (RCTImageLoaderCancellationBlock)_loadURLRequest : (NSURLRequest *)request
466
466
progressBlock : (RCTImageLoaderProgressBlock)progressHandler
467
- completionBlock : (void (^)(NSError *error, id imageOrData, NSString *fetchDate, NSString *cacheControl ))completionHandler
467
+ completionBlock : (void (^)(NSError *error, id imageOrData, NSURLResponse *response ))completionHandler
468
468
{
469
469
// Check if networking module is available
470
470
if (RCT_DEBUG && ![_bridge respondsToSelector: @selector (networking )]) {
@@ -486,36 +486,31 @@ - (RCTImageLoaderCancellationBlock)_loadURLRequest:(NSURLRequest *)request
486
486
RCTURLRequestCompletionBlock processResponse = ^(NSURLResponse *response, NSData *data, NSError *error) {
487
487
// Check for system errors
488
488
if (error) {
489
- completionHandler (error, nil , nil , nil );
489
+ completionHandler (error, nil , response );
490
490
return ;
491
491
} else if (!response) {
492
- completionHandler (RCTErrorWithMessage (@" Response metadata error" ), nil , nil , nil );
492
+ completionHandler (RCTErrorWithMessage (@" Response metadata error" ), nil , response );
493
493
return ;
494
494
} else if (!data) {
495
- completionHandler (RCTErrorWithMessage (@" Unknown image download error" ), nil , nil , nil );
495
+ completionHandler (RCTErrorWithMessage (@" Unknown image download error" ), nil , response );
496
496
return ;
497
497
}
498
498
499
499
// Check for http errors
500
- NSString *responseDate;
501
- NSString *cacheControl;
502
500
if ([response isKindOfClass: [NSHTTPURLResponse class ]]) {
503
501
NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode ;
504
502
if (statusCode != 200 ) {
505
503
NSString *errorMessage = [NSString stringWithFormat: @" Failed to load %@ " , response.URL];
506
504
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : errorMessage};
507
505
completionHandler ([[NSError alloc ] initWithDomain: NSURLErrorDomain
508
506
code: statusCode
509
- userInfo: userInfo], nil , nil , nil );
507
+ userInfo: userInfo], nil , response );
510
508
return ;
511
509
}
512
-
513
- responseDate = ((NSHTTPURLResponse *)response).allHeaderFields [@" Date" ];
514
- cacheControl = ((NSHTTPURLResponse *)response).allHeaderFields [@" Cache-Control" ];
515
510
}
516
511
517
512
// Call handler
518
- completionHandler (nil , data, responseDate, cacheControl );
513
+ completionHandler (nil , data, response );
519
514
};
520
515
521
516
// Download image
@@ -537,7 +532,7 @@ - (RCTImageLoaderCancellationBlock)_loadURLRequest:(NSURLRequest *)request
537
532
} else {
538
533
someError = RCTErrorWithMessage (@" Unknown image download error" );
539
534
}
540
- completionHandler (someError, nil , nil , nil );
535
+ completionHandler (someError, nil , response );
541
536
[strongSelf dequeueTasks ];
542
537
return ;
543
538
}
@@ -603,7 +598,7 @@ - (RCTImageLoaderCancellationBlock)loadImageWithURLRequest:(NSURLRequest *)image
603
598
};
604
599
605
600
__weak RCTImageLoader *weakSelf = self;
606
- void (^completionHandler)(NSError *, id , BOOL , NSString *, NSString * ) = ^(NSError *error, id imageOrData, BOOL cacheResult, NSString *fetchDate, NSString *cacheControl ) {
601
+ void (^completionHandler)(NSError *, id , BOOL , NSURLResponse * ) = ^(NSError *error, id imageOrData, BOOL cacheResult, NSURLResponse *response ) {
607
602
__typeof (self) strongSelf = weakSelf;
608
603
if (atomic_load (&cancelled) || !strongSelf) {
609
604
return ;
@@ -623,8 +618,7 @@ - (RCTImageLoaderCancellationBlock)loadImageWithURLRequest:(NSURLRequest *)image
623
618
size: size
624
619
scale: scale
625
620
resizeMode: resizeMode
626
- responseDate: fetchDate
627
- cacheControl: cacheControl];
621
+ response: response];
628
622
}
629
623
630
624
cancelLoad = nil ;
@@ -758,7 +752,7 @@ - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)data
758
752
- (RCTImageLoaderCancellationBlock)getImageSizeForURLRequest : (NSURLRequest *)imageURLRequest
759
753
block : (void (^)(NSError *error, CGSize size))callback
760
754
{
761
- void (^completion)(NSError *, id , BOOL , NSString *, NSString * ) = ^(NSError *error, id imageOrData, BOOL cacheResult, NSString *fetchDate, NSString *cacheControl ) {
755
+ void (^completion)(NSError *, id , BOOL , NSURLResponse * ) = ^(NSError *error, id imageOrData, BOOL cacheResult, NSURLResponse *response ) {
762
756
CGSize size;
763
757
if ([imageOrData isKindOfClass: [NSData class ]]) {
764
758
NSDictionary *meta = RCTGetImageMetadata (imageOrData);
0 commit comments