diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c7b3a0cc..1ce08a0564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## unreleased * BraintreeThreeDSecure * Add error code and error message for `exceededTimeoutLimit` -* Prevent duplicate outbound `v1/configuration` requests +* BraintreeCore + * Prevent duplicate outbound `v1/configuration` requests + * Add network timeout of 30 seconds ## 6.23.0 (2024-07-15) * BraintreeShopperInsights (BETA) diff --git a/Sources/BraintreeCore/BTHTTP.swift b/Sources/BraintreeCore/BTHTTP.swift index e67b33e256..7815e4e310 100644 --- a/Sources/BraintreeCore/BTHTTP.swift +++ b/Sources/BraintreeCore/BTHTTP.swift @@ -26,6 +26,8 @@ class BTHTTP: NSObject, URLSessionTaskDelegate { lazy var session: URLSession = { let configuration = URLSessionConfiguration.ephemeral configuration.httpAdditionalHeaders = defaultHeaders + configuration.timeoutIntervalForRequest = 30 + configuration.timeoutIntervalForResource = 30 let delegateQueue = OperationQueue() delegateQueue.name = "com.braintreepayments.BTHTTP" diff --git a/UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift b/UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift index b38ae3c61f..4a63babe51 100644 --- a/UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift +++ b/UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift @@ -779,6 +779,12 @@ final class BTHTTP_Tests: XCTestCase { XCTAssertNotNil(mockDelegate.receivedStartTime) XCTAssertNotNil(mockDelegate.receivedEndTime) } + + func testURLSessionConfiguration_hasCustomTimeoutSettings() { + let sut = BTHTTP(authorization: fakeTokenizationKey) + XCTAssertEqual(sut.session.configuration.timeoutIntervalForRequest, 30) + XCTAssertEqual(sut.session.configuration.timeoutIntervalForRequest, 30) + } // MARK: - Helper Methods