@@ -346,7 +346,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
346346 resizeMode : (RCTResizeMode)resizeMode
347347 progressBlock : (RCTImageLoaderProgressBlock)progressHandler
348348 partialLoadBlock : (RCTImageLoaderPartialLoadBlock)partialLoadHandler
349- completionBlock : (void (^)(NSError *error, id imageOrData, BOOL cacheResult, NSURLResponse *response ))completionBlock
349+ completionBlock : (void (^)(NSError *error, id imageOrData, BOOL cacheResult, NSString *fetchDate, NSString *cacheControl ))completionBlock
350350{
351351 {
352352 NSMutableURLRequest *mutableRequest = [request mutableCopy ];
@@ -375,7 +375,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
375375 __block atomic_bool cancelled = ATOMIC_VAR_INIT (NO );
376376 // TODO: Protect this variable shared between threads.
377377 __block dispatch_block_t cancelLoad = nil ;
378- void (^completionHandler)(NSError *, id , NSURLResponse * ) = ^(NSError *error, id imageOrData, NSURLResponse *response ) {
378+ void (^completionHandler)(NSError *, id , NSString *, NSString * ) = ^(NSError *error, id imageOrData, NSString *fetchDate, NSString *cacheControl ) {
379379 cancelLoad = nil ;
380380
381381 // If we've received an image, we should try to set it synchronously,
@@ -385,11 +385,11 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
385385 // expecting it, and may do expensive post-processing in the callback
386386 dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
387387 if (!atomic_load (&cancelled)) {
388- completionBlock (error, imageOrData, cacheResult, response );
388+ completionBlock (error, imageOrData, cacheResult, fetchDate, cacheControl );
389389 }
390390 });
391391 } else if (!atomic_load (&cancelled)) {
392- completionBlock (error, imageOrData, cacheResult, response );
392+ completionBlock (error, imageOrData, cacheResult, fetchDate, cacheControl );
393393 }
394394 };
395395
@@ -403,7 +403,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
403403 progressHandler: progressHandler
404404 partialLoadHandler: partialLoadHandler
405405 completionHandler: ^(NSError *error, UIImage *image){
406- completionHandler (error, image, nil );
406+ completionHandler (error, image, nil , nil );
407407 }];
408408 }
409409
@@ -427,7 +427,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
427427 progressHandler: progressHandler
428428 partialLoadHandler: partialLoadHandler
429429 completionHandler: ^(NSError *error, UIImage *image) {
430- completionHandler (error, image, nil );
430+ completionHandler (error, image, nil , nil );
431431 }];
432432 } else {
433433 UIImage *image;
@@ -439,7 +439,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
439439 }
440440
441441 if (image) {
442- completionHandler (nil , image, nil );
442+ completionHandler (nil , image, nil , nil );
443443 } else {
444444 // Use networking module to load image
445445 cancelLoad = [strongSelf _loadURLRequest: request
@@ -464,7 +464,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
464464
465465- (RCTImageLoaderCancellationBlock)_loadURLRequest : (NSURLRequest *)request
466466 progressBlock : (RCTImageLoaderProgressBlock)progressHandler
467- completionBlock : (void (^)(NSError *error, id imageOrData, NSURLResponse *response ))completionHandler
467+ completionBlock : (void (^)(NSError *error, id imageOrData, NSString *fetchDate, NSString *cacheControl ))completionHandler
468468{
469469 // Check if networking module is available
470470 if (RCT_DEBUG && ![_bridge respondsToSelector: @selector (networking )]) {
@@ -486,31 +486,36 @@ - (RCTImageLoaderCancellationBlock)_loadURLRequest:(NSURLRequest *)request
486486 RCTURLRequestCompletionBlock processResponse = ^(NSURLResponse *response, NSData *data, NSError *error) {
487487 // Check for system errors
488488 if (error) {
489- completionHandler (error, nil , response );
489+ completionHandler (error, nil , nil , nil );
490490 return ;
491491 } else if (!response) {
492- completionHandler (RCTErrorWithMessage (@" Response metadata error" ), nil , response );
492+ completionHandler (RCTErrorWithMessage (@" Response metadata error" ), nil , nil , nil );
493493 return ;
494494 } else if (!data) {
495- completionHandler (RCTErrorWithMessage (@" Unknown image download error" ), nil , response );
495+ completionHandler (RCTErrorWithMessage (@" Unknown image download error" ), nil , nil , nil );
496496 return ;
497497 }
498498
499499 // Check for http errors
500+ NSString *responseDate;
501+ NSString *cacheControl;
500502 if ([response isKindOfClass: [NSHTTPURLResponse class ]]) {
501503 NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode ;
502504 if (statusCode != 200 ) {
503505 NSString *errorMessage = [NSString stringWithFormat: @" Failed to load %@ " , response.URL];
504506 NSDictionary *userInfo = @{NSLocalizedDescriptionKey : errorMessage};
505507 completionHandler ([[NSError alloc ] initWithDomain: NSURLErrorDomain
506508 code: statusCode
507- userInfo: userInfo], nil , response );
509+ userInfo: userInfo], nil , nil , nil );
508510 return ;
509511 }
512+
513+ responseDate = ((NSHTTPURLResponse *)response).allHeaderFields [@" Date" ];
514+ cacheControl = ((NSHTTPURLResponse *)response).allHeaderFields [@" Cache-Control" ];
510515 }
511516
512517 // Call handler
513- completionHandler (nil , data, response );
518+ completionHandler (nil , data, responseDate, cacheControl );
514519 };
515520
516521 // Download image
@@ -532,7 +537,7 @@ - (RCTImageLoaderCancellationBlock)_loadURLRequest:(NSURLRequest *)request
532537 } else {
533538 someError = RCTErrorWithMessage (@" Unknown image download error" );
534539 }
535- completionHandler (someError, nil , response );
540+ completionHandler (someError, nil , nil , nil );
536541 [strongSelf dequeueTasks ];
537542 return ;
538543 }
@@ -598,7 +603,7 @@ - (RCTImageLoaderCancellationBlock)loadImageWithURLRequest:(NSURLRequest *)image
598603 };
599604
600605 __weak RCTImageLoader *weakSelf = self;
601- void (^completionHandler)(NSError *, id , BOOL , NSURLResponse * ) = ^(NSError *error, id imageOrData, BOOL cacheResult, NSURLResponse *response ) {
606+ void (^completionHandler)(NSError *, id , BOOL , NSString *, NSString * ) = ^(NSError *error, id imageOrData, BOOL cacheResult, NSString *fetchDate, NSString *cacheControl ) {
602607 __typeof (self) strongSelf = weakSelf;
603608 if (atomic_load (&cancelled) || !strongSelf) {
604609 return ;
@@ -618,7 +623,8 @@ - (RCTImageLoaderCancellationBlock)loadImageWithURLRequest:(NSURLRequest *)image
618623 size: size
619624 scale: scale
620625 resizeMode: resizeMode
621- response: response];
626+ responseDate: fetchDate
627+ cacheControl: cacheControl];
622628 }
623629
624630 cancelLoad = nil ;
@@ -752,7 +758,7 @@ - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)data
752758- (RCTImageLoaderCancellationBlock)getImageSizeForURLRequest : (NSURLRequest *)imageURLRequest
753759 block : (void (^)(NSError *error, CGSize size))callback
754760{
755- void (^completion)(NSError *, id , BOOL , NSURLResponse * ) = ^(NSError *error, id imageOrData, BOOL cacheResult, NSURLResponse *response ) {
761+ void (^completion)(NSError *, id , BOOL , NSString *, NSString * ) = ^(NSError *error, id imageOrData, BOOL cacheResult, NSString *fetchDate, NSString *cacheControl ) {
756762 CGSize size;
757763 if ([imageOrData isKindOfClass: [NSData class ]]) {
758764 NSDictionary *meta = RCTGetImageMetadata (imageOrData);
0 commit comments