Skip to content

Commit a64abfe

Browse files
authored
chore: API requests do a 10s timeoutInterval instead of 60s (#113)
1 parent d3a3761 commit a64abfe

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Next
22

3+
- API requests do a 10s timeoutInterval instead of 60s [#113](https://github.com/PostHog/posthog-ios/pull/113)
4+
35
## 3.2.1 - 2024-02-26
46

57
- PrivacyInfo manifest set in the SPM and CocoaPods config [#112](https://github.com/PostHog/posthog-ios/pull/112)

PostHog/PostHogApi.swift

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import Foundation
1010
class PostHogApi {
1111
private let config: PostHogConfig
1212

13+
// default is 60s but we do 10s
14+
private let defaultTimeout: TimeInterval = 10
15+
1316
init(_ config: PostHogConfig) {
1417
self.config = config
1518
}
@@ -25,6 +28,13 @@ class PostHogApi {
2528
return config
2629
}
2730

31+
private func getURL(_ url: URL) -> URLRequest {
32+
var request = URLRequest(url: url)
33+
request.httpMethod = "POST"
34+
request.timeoutInterval = defaultTimeout
35+
return request
36+
}
37+
2838
func batch(events: [PostHogEvent], completion: @escaping (PostHogBatchUploadInfo) -> Void) {
2939
guard let url = URL(string: "batch", relativeTo: config.host) else {
3040
hedgeLog("Malformed batch URL error.")
@@ -37,8 +47,7 @@ class PostHogApi {
3747
headers["Content-Encoding"] = "gzip"
3848
config.httpAdditionalHeaders = headers
3949

40-
var request = URLRequest(url: url)
41-
request.httpMethod = "POST"
50+
let request = getURL(url)
4251

4352
let toSend: [String: Any] = [
4453
"api_key": self.config.apiKey,
@@ -99,8 +108,7 @@ class PostHogApi {
99108

100109
let config = sessionConfig()
101110

102-
var request = URLRequest(url: url)
103-
request.httpMethod = "POST"
111+
let request = getURL(url)
104112

105113
let toSend: [String: Any] = [
106114
"api_key": self.config.apiKey,

0 commit comments

Comments
 (0)