Skip to content

Commit f3cd96f

Browse files
authored
Merge pull request #1589 from iothmane/pr_sr6369
2 parents 2dbf0fc + 83ee10a commit f3cd96f

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

Foundation/URLSession/Configuration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal extension URLSession {
3939
let allowsCellularAccess: Bool
4040

4141
/// allows background tasks to be scheduled at the discretion of the system for optimal performance.
42-
let discretionary: Bool
42+
let isDiscretionary: Bool
4343

4444
/// The proxy dictionary, as described by <CFNetwork/CFHTTPStream.h>
4545
let connectionProxyDictionary: [AnyHashable : Any]?
@@ -83,7 +83,7 @@ internal extension URLSession._Configuration {
8383
timeoutIntervalForResource = config.timeoutIntervalForResource
8484
networkServiceType = config.networkServiceType
8585
allowsCellularAccess = config.allowsCellularAccess
86-
discretionary = config.discretionary
86+
isDiscretionary = config.isDiscretionary
8787
connectionProxyDictionary = config.connectionProxyDictionary
8888
httpShouldUsePipelining = config.httpShouldUsePipelining
8989
httpShouldSetCookies = config.httpShouldSetCookies

Foundation/URLSession/URLSessionConfiguration.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ open class URLSessionConfiguration : NSObject, NSCopying {
3838
self.timeoutIntervalForResource = 604800
3939
self.networkServiceType = .default
4040
self.allowsCellularAccess = true
41-
self.discretionary = false
41+
self.isDiscretionary = false
4242
self.httpShouldUsePipelining = false
4343
self.httpShouldSetCookies = true
4444
self.httpCookieAcceptPolicy = .onlyFromMainDocumentDomain
@@ -57,7 +57,7 @@ open class URLSessionConfiguration : NSObject, NSCopying {
5757
timeoutIntervalForResource: TimeInterval,
5858
networkServiceType: URLRequest.NetworkServiceType,
5959
allowsCellularAccess: Bool,
60-
discretionary: Bool,
60+
isDiscretionary: Bool,
6161
connectionProxyDictionary: [AnyHashable:Any]?,
6262
httpShouldUsePipelining: Bool,
6363
httpShouldSetCookies: Bool,
@@ -76,7 +76,7 @@ open class URLSessionConfiguration : NSObject, NSCopying {
7676
self.timeoutIntervalForResource = timeoutIntervalForResource
7777
self.networkServiceType = networkServiceType
7878
self.allowsCellularAccess = allowsCellularAccess
79-
self.discretionary = discretionary
79+
self.isDiscretionary = isDiscretionary
8080
self.connectionProxyDictionary = connectionProxyDictionary
8181
self.httpShouldUsePipelining = httpShouldUsePipelining
8282
self.httpShouldSetCookies = httpShouldSetCookies
@@ -102,7 +102,7 @@ open class URLSessionConfiguration : NSObject, NSCopying {
102102
timeoutIntervalForResource: timeoutIntervalForResource,
103103
networkServiceType: networkServiceType,
104104
allowsCellularAccess: allowsCellularAccess,
105-
discretionary: discretionary,
105+
isDiscretionary: isDiscretionary,
106106
connectionProxyDictionary: connectionProxyDictionary,
107107
httpShouldUsePipelining: httpShouldUsePipelining,
108108
httpShouldSetCookies: httpShouldSetCookies,
@@ -142,7 +142,7 @@ open class URLSessionConfiguration : NSObject, NSCopying {
142142
open var allowsCellularAccess: Bool
143143

144144
/* allows background tasks to be scheduled at the discretion of the system for optimal performance. */
145-
open var discretionary: Bool
145+
open var isDiscretionary: Bool
146146

147147
/* The identifier of the shared data container into which files in background sessions should be downloaded.
148148
* App extensions wishing to use background sessions *must* set this property to a valid container identifier, or

TestFoundation/TestURLSession.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class TestURLSession : LoopbackServerTest {
4141
("test_cookiesStorage", test_cookiesStorage),
4242
("test_setCookies", test_setCookies),
4343
("test_dontSetCookies", test_dontSetCookies),
44+
("test_initURLSessionConfiguration", test_initURLSessionConfiguration),
4445
]
4546
}
4647

@@ -597,6 +598,40 @@ class TestURLSession : LoopbackServerTest {
597598
task.resume()
598599
waitForExpectations(timeout: 30)
599600
}
601+
602+
// Validate that the properties are correctly set
603+
func test_initURLSessionConfiguration() {
604+
let config = URLSessionConfiguration.default
605+
config.requestCachePolicy = .useProtocolCachePolicy
606+
config.timeoutIntervalForRequest = 30
607+
config.timeoutIntervalForResource = 604800
608+
config.networkServiceType = .default
609+
config.allowsCellularAccess = false
610+
config.isDiscretionary = true
611+
config.httpShouldUsePipelining = true
612+
config.httpShouldSetCookies = true
613+
config.httpCookieAcceptPolicy = .always
614+
config.httpMaximumConnectionsPerHost = 2
615+
config.httpCookieStorage = HTTPCookieStorage.shared
616+
config.urlCredentialStorage = nil
617+
config.urlCache = nil
618+
config.shouldUseExtendedBackgroundIdleMode = true
619+
620+
XCTAssertEqual(config.requestCachePolicy, NSURLRequest.CachePolicy.useProtocolCachePolicy)
621+
XCTAssertEqual(config.timeoutIntervalForRequest, 30)
622+
XCTAssertEqual(config.timeoutIntervalForResource, 604800)
623+
XCTAssertEqual(config.networkServiceType, NSURLRequest.NetworkServiceType.default)
624+
XCTAssertEqual(config.allowsCellularAccess, false)
625+
XCTAssertEqual(config.isDiscretionary, true)
626+
XCTAssertEqual(config.httpShouldUsePipelining, true)
627+
XCTAssertEqual(config.httpShouldSetCookies, true)
628+
XCTAssertEqual(config.httpCookieAcceptPolicy, HTTPCookie.AcceptPolicy.always)
629+
XCTAssertEqual(config.httpMaximumConnectionsPerHost, 2)
630+
XCTAssertEqual(config.httpCookieStorage, HTTPCookieStorage.shared)
631+
XCTAssertEqual(config.urlCredentialStorage, nil)
632+
XCTAssertEqual(config.urlCache, nil)
633+
XCTAssertEqual(config.shouldUseExtendedBackgroundIdleMode, true)
634+
}
600635
}
601636

602637
class SharedDelegate: NSObject {

0 commit comments

Comments
 (0)