-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: wip add iOS code for raw request
- Loading branch information
Showing
10 changed files
with
392 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -760,9 +760,9 @@ | |
xmldoc "^1.1.2" | ||
|
||
"@react-native-community/cli-platform-ios@^5.0.1-alpha.0": | ||
version "5.0.1-alpha.1" | ||
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-ios/-/cli-platform-ios-5.0.1-alpha.1.tgz#4d919dc91829404ebd4717c9adc3b3f013152919" | ||
integrity sha512-X0odEhPYecSWjG+nNFN5tSxFQcfxS2rTOaMSmrHiqdlL8Bv57wCajtf5VhwanqhGt3eZ70y8oS9VdBRachxEpA== | ||
version "5.0.1-alpha.2" | ||
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-ios/-/cli-platform-ios-5.0.1-alpha.2.tgz#58ab0641355cbe68a0d1737dde8c7d66eb0c0e39" | ||
integrity sha512-W15A75j+4bx6qbcapFia1A0M+W3JAt7Bc4VgEYvxDDRI62EsSHk1k6ZBNxs/j0cDPSYF9ZXHlRI+CWi3r9bTbQ== | ||
dependencies: | ||
"@react-native-community/cli-tools" "^5.0.1-alpha.1" | ||
chalk "^3.0.0" | ||
|
@@ -772,10 +772,10 @@ | |
plist "^3.0.1" | ||
xcode "^2.0.0" | ||
|
||
"@react-native-community/cli-server-api@^5.0.1-alpha.1": | ||
version "5.0.1-alpha.1" | ||
resolved "https://registry.yarnpkg.com/@react-native-community/cli-server-api/-/cli-server-api-5.0.1-alpha.1.tgz#2b830411ca9b6922da67ea32c3e1c0492aa001fe" | ||
integrity sha512-Ev5drbVEnvC3EB3GCn5sog1fOn+4ULC/TUjWEDe9Ld93na7W1cYb+qAEMRP8hxZUf6R3qCRsFi6JY42qtqa+qQ== | ||
"@react-native-community/cli-server-api@^5.0.1-alpha.2": | ||
version "5.0.1-alpha.2" | ||
resolved "https://registry.yarnpkg.com/@react-native-community/cli-server-api/-/cli-server-api-5.0.1-alpha.2.tgz#a82557273bad99d188682169892aaa4b283ba149" | ||
integrity sha512-qzjoLF51GmvUHQrcJZE+wD3bTmgnTNOnGBU6z4terKmPdt/EBBSUkdXc6ScWWRF6oWP+xpxLZ//tKic2v2f+ag== | ||
dependencies: | ||
"@react-native-community/cli-debugger-ui" "^5.0.1-alpha.1" | ||
"@react-native-community/cli-tools" "^5.0.1-alpha.1" | ||
|
@@ -807,13 +807,13 @@ | |
ora "^3.4.0" | ||
|
||
"@react-native-community/cli@^5.0.1-alpha.0": | ||
version "5.0.1-alpha.1" | ||
resolved "https://registry.yarnpkg.com/@react-native-community/cli/-/cli-5.0.1-alpha.1.tgz#68a1887477e66a6d5206bd951b241730e1c0cbdc" | ||
integrity sha512-XmOqkg9noF/jaHujoBLifR1VCmisXZbTr9Lt3S2/QBgDg0jWDLAuraZC58yuBuzUTcG3+kfbD61rW3AWtnx8fA== | ||
version "5.0.1-alpha.2" | ||
resolved "https://registry.yarnpkg.com/@react-native-community/cli/-/cli-5.0.1-alpha.2.tgz#7e78378120fd4e264e4b577cbcf5e52b5beaa53b" | ||
integrity sha512-PP22TVV2VyELXhAX4PcBisasssastSEx23XDklfPoCPIXD2QgGC7y39n/b5I9tOzKi2qYswCEAcDpwXYwevGOg== | ||
dependencies: | ||
"@react-native-community/cli-debugger-ui" "^5.0.1-alpha.1" | ||
"@react-native-community/cli-hermes" "^5.0.1-alpha.1" | ||
"@react-native-community/cli-server-api" "^5.0.1-alpha.1" | ||
"@react-native-community/cli-server-api" "^5.0.1-alpha.2" | ||
"@react-native-community/cli-tools" "^5.0.1-alpha.1" | ||
"@react-native-community/cli-types" "^5.0.1-alpha.1" | ||
appdirsjs "^1.2.4" | ||
|
@@ -1328,9 +1328,9 @@ camelcase@^6.0.0: | |
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== | ||
|
||
caniuse-lite@^1.0.30001181: | ||
version "1.0.30001200" | ||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001200.tgz#25435af6ba907c2a9c86d21ce84950d4824e6620" | ||
integrity sha512-ic/jXfa6tgiPBAISWk16jRI2q8YfjxHnSG7ddSL1ptrIP8Uy11SayFrjXRAk3NumHpDb21fdTkbTxb/hOrFrnQ== | ||
version "1.0.30001202" | ||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001202.tgz#4cb3bd5e8a808e8cd89e4e66c549989bc8137201" | ||
integrity sha512-ZcijQNqrcF8JNLjzvEiXqX4JUYxoZa7Pvcsd9UD8Kz4TvhTonOSNRsK+qtvpVL4l6+T1Rh4LFtLfnNWg6BGWCQ== | ||
|
||
capture-exit@^2.0.0: | ||
version "2.0.0" | ||
|
@@ -1644,9 +1644,9 @@ [email protected]: | |
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= | ||
|
||
electron-to-chromium@^1.3.649: | ||
version "1.3.688" | ||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.688.tgz#0ba54a3e77fca6561a337e6cca959b75db8683b0" | ||
integrity sha512-tbKinYX7BomVBcWHzwGolzv3kqCdk/vQ36ao3MC8tQMXqs1ZpevYU2RTr7+hkDvGWtoQbe+nvvl+GfMFmRna/A== | ||
version "1.3.691" | ||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.691.tgz#a671eaf135a3ccec0915eb8d844a0952aba79f3b" | ||
integrity sha512-ZqiO69KImmOGCyoH0icQPU3SndJiW93juEvf63gQngyhODO6SpQIPMTOHldtCs5DS5GMKvAkquk230E2zt2vpw== | ||
|
||
emoji-regex@^8.0.0: | ||
version "8.0.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) Ely Deckers. | ||
// | ||
// This source code is licensed under the MPL-2.0 license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
import Foundation | ||
|
||
open class BlobSender: NSObject { | ||
static func filterHeaders(unfilteredHeaders: NSDictionary) -> NSDictionary { | ||
Dictionary(uniqueKeysWithValues: unfilteredHeaders | ||
.map { key, value in (key as? String, value as? String) } | ||
.filter({ $0.1 != nil })) | ||
.mapValues { $0! } as NSDictionary | ||
} | ||
|
||
static func isValidTargetValue(_ value: String) -> Bool { | ||
return Constants.targetValues.contains(value) | ||
} | ||
|
||
static func buildRequestDataForFileSend( | ||
method: String, | ||
url: URL, | ||
absoluteFilePath: String, | ||
headers: NSDictionary) throws -> (URLRequest, Data) { | ||
var request = URLRequest(url: url) | ||
request.httpMethod = method | ||
|
||
for (key, value) in headers { | ||
if let headerKey = key as? String, let headerValue = value as? String { | ||
request.setValue( | ||
headerValue, | ||
forHTTPHeaderField: headerKey) | ||
} | ||
} | ||
|
||
let fileUrl = URL(string: absoluteFilePath)! | ||
|
||
let fileData = try Data(contentsOf: fileUrl) | ||
|
||
return (request, fileData) | ||
} | ||
|
||
// swiftlint:disable function_body_length | ||
static func sendBlobFromValidatedParameters(parameters: SendParameters) -> | ||
Result<NSDictionary, BlobCourierError> { | ||
let sessionConfig = URLSessionConfiguration.default | ||
|
||
let group = DispatchGroup() | ||
let groupId = UUID().uuidString | ||
|
||
let queue = DispatchQueue.global() | ||
|
||
var result: Result<NSDictionary, BlobCourierError> = .success([:]) | ||
|
||
print("Entering group (id=\(groupId))") | ||
group.enter() | ||
|
||
var cancelObserver: NSObjectProtocol? | ||
|
||
queue.async(group: group) { | ||
let successfulResult = { (theResult: NSDictionary) -> Void in | ||
result = .success(theResult) | ||
|
||
print("Leaving group (id=\(groupId),status=resolve)") | ||
group.leave() | ||
} | ||
|
||
let failedResult = { (error: BlobCourierError) -> Void in | ||
result = .failure(error) | ||
|
||
print("Leaving group (id=\(groupId),status=reject)") | ||
group.leave() | ||
} | ||
|
||
let senderDelegate = | ||
SenderDelegate( | ||
taskId: parameters.taskId, | ||
returnResponse: parameters.returnResponse, | ||
progressIntervalMilliseconds: parameters.progressIntervalMilliseconds, | ||
resolve: successfulResult, | ||
reject: failedResult) | ||
|
||
let session = URLSession(configuration: sessionConfig, delegate: senderDelegate, delegateQueue: nil) | ||
|
||
let headers = parameters.headers | ||
|
||
do { | ||
let (request, fileData) = | ||
try buildRequestDataForFileSend( | ||
method: parameters.method, | ||
url: parameters.url, | ||
absoluteFilePath: parameters.absoluteFilePath, | ||
headers: headers) | ||
|
||
session.uploadTask(with: request, from: fileData).resume() | ||
|
||
cancelObserver = CancelController.registerCancelObserver( | ||
session: session, taskId: parameters.taskId) | ||
} catch { | ||
failedResult(Errors.createUnexpectedError(error: error)) | ||
} | ||
} | ||
|
||
print("Waiting for group (id=\(groupId))") | ||
group.wait() | ||
print("Left group (id=\(groupId))") | ||
|
||
NotificationCenter.default.removeObserver(cancelObserver) | ||
|
||
return result | ||
} | ||
// swiftlint:enable function_body_length | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Ely Deckers. | ||
// | ||
// This source code is licensed under the MPL-2.0 license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
import Foundation | ||
|
||
struct SendParameters { | ||
let absoluteFilePath: String | ||
let headers: NSDictionary | ||
let method: String | ||
let progressIntervalMilliseconds: Int | ||
let returnResponse: Bool | ||
let taskId: String | ||
let url: URL | ||
|
||
init( | ||
absoluteFilePath: String, | ||
headers: NSDictionary, | ||
method: String, | ||
progressIntervalMilliseconds: Int, | ||
returnResponse: Bool, | ||
taskId: String, | ||
url: URL) { | ||
self.absoluteFilePath = absoluteFilePath | ||
self.headers = headers | ||
self.method = method | ||
self.progressIntervalMilliseconds = progressIntervalMilliseconds | ||
self.returnResponse = returnResponse | ||
self.taskId = taskId | ||
self.url = url | ||
} | ||
} |
Oops, something went wrong.