Skip to content

Commit 2798d05

Browse files
committed
Set custom HTTP request header for reporting (#67)
1 parent 9ec4323 commit 2798d05

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

Sources/MuxUploadSDK/Extensions/NSMutableURLRequest+Reporting.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import Foundation
77
extension NSMutableURLRequest {
88
static func makeJSONPost(
99
url: URL,
10-
httpBody: Data
10+
httpBody: Data,
11+
additionalHTTPHeaders: [String: String]
1112
) -> NSMutableURLRequest {
1213
let request = NSMutableURLRequest(
1314
url: url,
@@ -18,6 +19,10 @@ extension NSMutableURLRequest {
1819
request.httpMethod = "POST"
1920
request.setValue("application/json", forHTTPHeaderField: "Accept")
2021
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
22+
for keypair in additionalHTTPHeaders {
23+
request.setValue(keypair.value, forHTTPHeaderField: keypair.key)
24+
}
25+
2126
request.httpBody = httpBody
2227

2328
return request

Sources/MuxUploadSDK/InternalUtilities/Reporting/Reporter.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Reporter: NSObject {
2020

2121
var sessionID: String = UUID().uuidString
2222
var url: URL
23+
var additionalHTTPHeaders: [String: String] {
24+
["x-litix-sdk": "swift-upload-sdk"]
25+
}
2326

2427
// TODO: Set these using dependency Injection
2528
var locale: Locale {
@@ -65,7 +68,8 @@ class Reporter: NSObject {
6568

6669
let request = NSMutableURLRequest.makeJSONPost(
6770
url: url,
68-
httpBody: httpBody
71+
httpBody: httpBody,
72+
additionalHTTPHeaders: additionalHTTPHeaders
6973
)
7074

7175
guard let dataTask = session?.dataTask(
@@ -268,7 +272,8 @@ extension Reporter: URLSessionDelegate, URLSessionTaskDelegate {
268272
// for any weirdness
269273
let request = NSMutableURLRequest.makeJSONPost(
270274
url: redirectURL,
271-
httpBody: httpBody
275+
httpBody: httpBody,
276+
additionalHTTPHeaders: additionalHTTPHeaders
272277
)
273278

274279
completionHandler(request as URLRequest)

Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ public final class MuxUpload : Hashable, Equatable {
430430

431431
if self.manageBySDK {
432432
// See if there's anything in progress already
433-
fileWorker = uploadManager.findChunkedFileUploader(inputFileURL: videoFile)
433+
fileWorker = uploadManager.findChunkedFileUploader(
434+
inputFileURL: videoFile
435+
)
434436
}
435437
if fileWorker != nil && !forceRestart {
436438
MuxUploadSDK.logger?.warning("start() called but upload is already in progress")
@@ -613,9 +615,8 @@ public final class MuxUpload : Hashable, Equatable {
613615
)
614616
fileWorker.start()
615617
self.fileWorker = fileWorker
616-
<<<<<<< HEAD
617618
uploadManager.registerUpload(self)
618-
=======
619+
619620
let transportStatus = TransportStatus(
620621
progress: fileWorker.currentState.progress ?? Progress(),
621622
updatedTime: Date().timeIntervalSince1970,
@@ -626,7 +627,6 @@ public final class MuxUpload : Hashable, Equatable {
626627
startingTransportStatus: transportStatus
627628
)
628629
inputStatusHandler?(inputStatus)
629-
>>>>>>> 071c77b (Input standardization 2 (#41))
630630
}
631631

632632
func startNetworkTransport(

Sources/MuxUploadSDK/PublicAPI/UploadManager.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public final class UploadManager {
117117
}
118118

119119
internal func registerUpload(_ upload: MuxUpload) {
120+
120121
guard let fileWorker = upload.fileWorker else {
121122
// Only started uploads, aka uploads with a file
122123
// worker can be registered.
@@ -126,10 +127,6 @@ public final class UploadManager {
126127
}
127128

128129
uploadsByID.updateValue(upload, forKey: upload.id)
129-
}
130-
131-
internal func registerUploader(_ fileWorker: ChunkedFileUploader, withId id: String) {
132-
uploadsByID.updateValue(fileWorker, forKey: fileWorker.uploadInfo.id)
133130
fileWorker.addDelegate(withToken: UUID().uuidString, uploaderDelegate)
134131
Task.detached {
135132
await self.uploadActor.updateUpload(

0 commit comments

Comments
 (0)