Skip to content

Commit

Permalink
fix: update requestId for Idempotency when resending (#63)
Browse files Browse the repository at this point in the history
* fix: update requestId for Idempotency when resending

* add changelog
  • Loading branch information
cbaker6 authored Mar 2, 2023
1 parent 9c8f139 commit fd28500
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ __New features__
* The max connection attempts for LiveQuery can now be changed when initializing the SDK ([#43](https://github.com/netreconlab/Parse-Swift/pull/43)), thanks to [Corey Baker](https://github.com/cbaker6).

__Fixes__
* Fixed "Duplicate request" error when resending requests related to ipempotency ([#63](https://github.com/netreconlab/Parse-Swift/pull/63)), thanks to [Corey Baker](https://github.com/cbaker6).
* Fixed query count and withCount returning 0 when the SDK is configured to use GET for queries ([#61](https://github.com/netreconlab/Parse-Swift/pull/61)), thanks to [Corey Baker](https://github.com/cbaker6).
* Fixed ambiguous ParseAnalytics trackAppOpenned ([#55](https://github.com/netreconlab/Parse-Swift/pull/55)), thanks to [Corey Baker](https://github.com/cbaker6).
* Refactored playground mount to be "/parse" instead "/1". Also do not require url when decoding a ParseFile ([#52](https://github.com/netreconlab/Parse-Swift/pull/52)), thanks to [Corey Baker](https://github.com/cbaker6).
Expand Down
6 changes: 5 additions & 1 deletion Sources/ParseSwift/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public struct API {
}

headers["X-Parse-Client-Version"] = clientVersion()
headers["X-Parse-Request-Id"] = UUID().uuidString.lowercased()
headers["X-Parse-Request-Id"] = Self.createUniqueRequestId()

options.forEach { (option) in
switch option {
Expand Down Expand Up @@ -257,6 +257,10 @@ public struct API {
return headers
}

internal static func createUniqueRequestId() -> String {
UUID().uuidString.lowercased()
}

internal static func clientVersion() -> String {
ParseConstants.sdk+ParseConstants.version
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/ParseSwift/Extensions/URLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ internal extension URLSession {
}

callbackQueue.asyncAfter(deadline: .now() + delayInterval) {
// Update requestId in header for Idempotency
var request = request
if request.allHTTPHeaderFields?["X-Parse-Request-Id"] != nil {
request.allHTTPHeaderFields?["X-Parse-Request-Id"] = API.createUniqueRequestId()
}
self.dataTask(with: request,
callbackQueue: callbackQueue,
attempts: attempts,
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "5.0.0-beta.8"
static let version = "5.0.0-beta.9"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down

0 comments on commit fd28500

Please sign in to comment.