Skip to content

Commit

Permalink
chore: API requests do a 10s timeoutInterval instead of 60s (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Feb 29, 2024
1 parent d3a3761 commit a64abfe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- API requests do a 10s timeoutInterval instead of 60s [#113](https://github.com/PostHog/posthog-ios/pull/113)

## 3.2.1 - 2024-02-26

- PrivacyInfo manifest set in the SPM and CocoaPods config [#112](https://github.com/PostHog/posthog-ios/pull/112)
Expand Down
16 changes: 12 additions & 4 deletions PostHog/PostHogApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Foundation
class PostHogApi {
private let config: PostHogConfig

// default is 60s but we do 10s
private let defaultTimeout: TimeInterval = 10

init(_ config: PostHogConfig) {
self.config = config
}
Expand All @@ -25,6 +28,13 @@ class PostHogApi {
return config
}

private func getURL(_ url: URL) -> URLRequest {
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.timeoutInterval = defaultTimeout
return request
}

func batch(events: [PostHogEvent], completion: @escaping (PostHogBatchUploadInfo) -> Void) {
guard let url = URL(string: "batch", relativeTo: config.host) else {
hedgeLog("Malformed batch URL error.")
Expand All @@ -37,8 +47,7 @@ class PostHogApi {
headers["Content-Encoding"] = "gzip"
config.httpAdditionalHeaders = headers

var request = URLRequest(url: url)
request.httpMethod = "POST"
let request = getURL(url)

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

let config = sessionConfig()

var request = URLRequest(url: url)
request.httpMethod = "POST"
let request = getURL(url)

let toSend: [String: Any] = [
"api_key": self.config.apiKey,
Expand Down

0 comments on commit a64abfe

Please sign in to comment.