@@ -10,6 +10,9 @@ import Foundation
10
10
class PostHogApi {
11
11
private let config : PostHogConfig
12
12
13
+ // default is 60s but we do 10s
14
+ private let defaultTimeout : TimeInterval = 10
15
+
13
16
init ( _ config: PostHogConfig ) {
14
17
self . config = config
15
18
}
@@ -25,6 +28,13 @@ class PostHogApi {
25
28
return config
26
29
}
27
30
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
+
28
38
func batch( events: [ PostHogEvent ] , completion: @escaping ( PostHogBatchUploadInfo ) -> Void ) {
29
39
guard let url = URL ( string: " batch " , relativeTo: config. host) else {
30
40
hedgeLog ( " Malformed batch URL error. " )
@@ -37,8 +47,7 @@ class PostHogApi {
37
47
headers [ " Content-Encoding " ] = " gzip "
38
48
config. httpAdditionalHeaders = headers
39
49
40
- var request = URLRequest ( url: url)
41
- request. httpMethod = " POST "
50
+ let request = getURL ( url)
42
51
43
52
let toSend : [ String : Any ] = [
44
53
" api_key " : self . config. apiKey,
@@ -99,8 +108,7 @@ class PostHogApi {
99
108
100
109
let config = sessionConfig ( )
101
110
102
- var request = URLRequest ( url: url)
103
- request. httpMethod = " POST "
111
+ let request = getURL ( url)
104
112
105
113
let toSend : [ String : Any ] = [
106
114
" api_key " : self . config. apiKey,
0 commit comments