Skip to content

Commit fd28500

Browse files
authored
fix: update requestId for Idempotency when resending (#63)
* fix: update requestId for Idempotency when resending * add changelog
1 parent 9c8f139 commit fd28500

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ __New features__
3737
* 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).
3838

3939
__Fixes__
40+
* 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).
4041
* 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).
4142
* Fixed ambiguous ParseAnalytics trackAppOpenned ([#55](https://github.com/netreconlab/Parse-Swift/pull/55)), thanks to [Corey Baker](https://github.com/cbaker6).
4243
* 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).

Sources/ParseSwift/API/API.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public struct API {
219219
}
220220

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

224224
options.forEach { (option) in
225225
switch option {
@@ -257,6 +257,10 @@ public struct API {
257257
return headers
258258
}
259259

260+
internal static func createUniqueRequestId() -> String {
261+
UUID().uuidString.lowercased()
262+
}
263+
260264
internal static func clientVersion() -> String {
261265
ParseConstants.sdk+ParseConstants.version
262266
}

Sources/ParseSwift/Extensions/URLSession.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ internal extension URLSession {
213213
}
214214

215215
callbackQueue.asyncAfter(deadline: .now() + delayInterval) {
216+
// Update requestId in header for Idempotency
217+
var request = request
218+
if request.allHTTPHeaderFields?["X-Parse-Request-Id"] != nil {
219+
request.allHTTPHeaderFields?["X-Parse-Request-Id"] = API.createUniqueRequestId()
220+
}
216221
self.dataTask(with: request,
217222
callbackQueue: callbackQueue,
218223
attempts: attempts,

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.0.0-beta.8"
13+
static let version = "5.0.0-beta.9"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

0 commit comments

Comments
 (0)