From 77683c68d77fa3ea0156b2d921063d0b2d69eda0 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 9 Jul 2019 21:41:36 +0800 Subject: [PATCH 1/3] Set HTTPMaximumConnectionsPerHost to PINRemoteImageHTTPMaximumConnectionsPerHost only if user don't provide sessionConfiguration --- Source/Classes/PINRemoteImageManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Classes/PINRemoteImageManager.m b/Source/Classes/PINRemoteImageManager.m index 216baff0..d3daf93f 100644 --- a/Source/Classes/PINRemoteImageManager.m +++ b/Source/Classes/PINRemoteImageManager.m @@ -219,8 +219,8 @@ -(nonnull instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration * _sessionConfiguration.timeoutIntervalForRequest = PINRemoteImageManagerDefaultTimeout; _sessionConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData; _sessionConfiguration.URLCache = nil; + _sessionConfiguration.HTTPMaximumConnectionsPerHost = PINRemoteImageHTTPMaximumConnectionsPerHost; } - _sessionConfiguration.HTTPMaximumConnectionsPerHost = PINRemoteImageHTTPMaximumConnectionsPerHost; _callbackQueue = dispatch_queue_create("PINRemoteImageManagerCallbackQueue", DISPATCH_QUEUE_CONCURRENT); _lock = [[PINRemoteLock alloc] initWithName:@"PINRemoteImageManager"]; From 027281589f05b1904ee5a16ea15fd515443148ad Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 10 Jul 2019 09:24:51 +0800 Subject: [PATCH 2/3] Add documentation and test --- Source/Classes/PINRemoteImageManager.h | 5 +++++ Tests/PINRemoteImageTests.m | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Source/Classes/PINRemoteImageManager.h b/Source/Classes/PINRemoteImageManager.h index 801ece1e..53310483 100644 --- a/Source/Classes/PINRemoteImageManager.h +++ b/Source/Classes/PINRemoteImageManager.h @@ -167,6 +167,7 @@ typedef void(^PINRemoteImageManagerMetrics)(NSURL * __nonnull url, NSURLSession Create and return a PINRemoteImageManager created with the specified configuration. If configuration is nil, [NSURLSessionConfiguration defaultConfiguration] is used. Specify a custom configuration if you need to configure timeout values, cookie policies, additional HTTP headers, etc. @param sessionConfiguration The session configuration used to create the PINRemoteImageManager. @return A PINRemoteImageManager with the specified configuration. + @note If you provide your own `sessionConfiguration`, please attention `HTTPMaximumConnectionsPerHost` property, it may causes timeout when in conjunction with `maxNumberOfConcurrentDownloads` if you set a larger number to `maxNumberOfConcurrentDownloads` but smaller number to `HTTPMaximumConnectionsPerHost`. */ - (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)sessionConfiguration; @@ -175,6 +176,7 @@ typedef void(^PINRemoteImageManagerMetrics)(NSURL * __nonnull url, NSURLSession @param sessionConfiguration The session configuration used to create the PINRemoteImageManager. @param alternativeRepresentationProvider a delegate which conforms to the PINRemoteImageManagerAlternateRepresentationProvider protocol. Provide a delegate if you want to have non image results. The manager maintains a weak reference to the delegate. @see PINRemoteImageManagerAlternateRepresentationProvider for an example. @return A PINRemoteImageManager with the specified configuration. + @note If you provide your own `sessionConfiguration`, please attention `HTTPMaximumConnectionsPerHost` property, it may causes timeout when in conjunction with `maxNumberOfConcurrentDownloads` if you set a larger number to `maxNumberOfConcurrentDownloads` but smaller number to `HTTPMaximumConnectionsPerHost`. */ - (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)sessionConfiguration alternativeRepresentationProvider:(nullable id )alternativeRepresentationProvider; @@ -185,6 +187,7 @@ typedef void(^PINRemoteImageManagerMetrics)(NSURL * __nonnull url, NSURLSession @param alternateRepDelegate a delegate which conforms to the PINRemoteImageManagerAlternateRepresentationProvider protocol. Provide a delegate if you want to have non image results. The manager maintains a weak reference to the delegate. @see PINRemoteImageManagerAlternateRepresentationProvider for an example. @param imageCache Optional delegate which conforms to the PINRemoteImageCaching protocol. Provide a delegate if you want to control image caching. By default, image manager will use most appropriate implementation available (based on PINCache or NSCache, depending on subspec)@see PINRemoteImageBasicCache for an example. @return A PINRemoteImageManager with the specified configuration. + @note If you provide your own `sessionConfiguration`, please attention `HTTPMaximumConnectionsPerHost` property, it may causes timeout when in conjunction with `maxNumberOfConcurrentDownloads` if you set a larger number to `maxNumberOfConcurrentDownloads` but smaller number to `HTTPMaximumConnectionsPerHost`. */ - (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)sessionConfiguration alternativeRepresentationProvider:(nullable id )alternateRepDelegate @@ -197,6 +200,7 @@ typedef void(^PINRemoteImageManagerMetrics)(NSURL * __nonnull url, NSURLSession @param imageCache Optional delegate which conforms to the PINRemoteImageCaching protocol. Provide a delegate if you want to control image caching. By default, image manager will use most appropriate implementation available (based on PINCache or NSCache, depending on subspec)@see PINRemoteImageBasicCache for an example. @param managerConfiguration The configuration used to create the PINRemoteImageManager. @return A PINRemoteImageManager with the specified configuration. + @note If you provide your own `sessionConfiguration`, please attention `HTTPMaximumConnectionsPerHost` property, it may causes timeout when in conjunction with `maxNumberOfConcurrentDownloads` if you set a larger number to `maxNumberOfConcurrentDownloads` but smaller number to `HTTPMaximumConnectionsPerHost`. */ - (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)sessionConfiguration alternativeRepresentationProvider:(nullable id )alternateRepDelegate @@ -214,6 +218,7 @@ typedef void(^PINRemoteImageManagerMetrics)(NSURL * __nonnull url, NSURLSession Sets the shared instance of PINRemoteImageManager to an instance with the supplied configuration. If configuration is nil, [NSURLSessionConfiguration ephemeralSessionConfiguration] is used. You specify a custom configuration if you need to configure timeout values, cookie policies, additional HTTP headers, etc. This method should not be used if the shared instance has already been created. @param configuration The configuration used to create the PINRemoteImageManager. + @note If you provide your own `sessionConfiguration`, please attention `HTTPMaximumConnectionsPerHost` property, it may causes timeout when in conjunction with `maxNumberOfConcurrentDownloads` if you set a larger number to `maxNumberOfConcurrentDownloads` but smaller number to `HTTPMaximumConnectionsPerHost`. */ + (void)setSharedImageManagerWithConfiguration:(nullable NSURLSessionConfiguration *)configuration; diff --git a/Tests/PINRemoteImageTests.m b/Tests/PINRemoteImageTests.m index e4a67d66..e0823b7e 100644 --- a/Tests/PINRemoteImageTests.m +++ b/Tests/PINRemoteImageTests.m @@ -263,6 +263,25 @@ - (void)testInitWithConfiguration XCTAssert([self.imageManager.sessionManager.session.configuration.HTTPAdditionalHeaders isEqualToDictionary:@{ @"Authorization" : @"Pinterest 123456" }]); } +- (void)testSessionConfigurationOfHTTPMaximumConnectionsPerHost +{ + { + // User has custom `HTTPMaximumConnectionsPerHost` + NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; + configuration.HTTPMaximumConnectionsPerHost = 5; + self.imageManager = [[PINRemoteImageManager alloc] initWithSessionConfiguration:configuration]; + NSURLSessionConfiguration *sessionManagerConfiguration = self.imageManager.sessionManager.session.configuration; + XCTAssert(configuration.HTTPMaximumConnectionsPerHost == sessionManagerConfiguration.HTTPMaximumConnectionsPerHost); + } + + { + // Using image manager provided `HTTPMaximumConnectionsPerHost` value + self.imageManager = [[PINRemoteImageManager alloc] initWithSessionConfiguration:nil]; + NSURLSessionConfiguration *sessionManagerConfiguration = self.imageManager.sessionManager.session.configuration; + XCTAssert(sessionManagerConfiguration.HTTPMaximumConnectionsPerHost == PINRemoteImageHTTPMaximumConnectionsPerHost); + } +} + - (void)testCustomHeaderIsAddedToImageRequests { XCTestExpectation *expectation = [self expectationWithDescription:@"Custom header was added to image request"]; From 64511b1cc91c4aa2359d5c912f9450d109710474 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 11 Jul 2019 15:50:44 +0800 Subject: [PATCH 3/3] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36c90fdf..80dcc4c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - [new] Add PINRemoteImageManagerConfiguration configuration object. [#492](https://github.com/pinterest/PINRemoteImage/pull/492) [rqueue](https://github.com/rqueue) - [fixed] Fixes blending in animated WebP images. [#507](https://github.com/pinterest/PINRemoteImage/pull/507) [garrettmoon](https://github.com/garrettmoon) - [fixed] Fixes support in PINAnimatedImageView for WebP animated images. [#507](https://github.com/pinterest/PINRemoteImage/pull/507) [garrettmoon](https://github.com/garrettmoon) +- [fixed] Set HTTPMaximumConnectionsPerHost to PINRemoteImageHTTPMaximumConnectionsPerHost only if user don't provide sessionConfiguration. [#516](https://github.com/pinterest/PINRemoteImage/pull/516) [zhongwuzw](https://github.com/zhongwuzw) ## 3.0.0 Beta 14 - [fixed] Re-enable warnings check [#506](https://github.com/pinterest/PINRemoteImage/pull/506) [garrettmoon](https://github.com/garrettmoon)