Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 1b93636

Browse files
Update Async-Http-Client to version 1.0.0
1 parent 7be33c3 commit 1b93636

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/Packages
44
/*.xcodeproj
55
default.profraw
6+
.swiftpm

Package.resolved

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ let package = Package(
1616
// Dependencies declare other packages that this package depends on.
1717
//.package(path: "../aws-lambda-swift-sprinter-core/"),
1818
.package(url: "https://github.com/swift-sprinter/aws-lambda-swift-sprinter-core", from: "1.0.0-alpha.2"),
19-
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.0.0-alpha.4"),
19+
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.0.0"),
20+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.8.0"),
2021
],
2122
targets: [
2223
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2324
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2425
.target(
2526
name: "LambdaSwiftSprinterNioPlugin",
26-
dependencies: ["LambdaSwiftSprinter", "AsyncHTTPClient"]
27+
dependencies: ["LambdaSwiftSprinter", "AsyncHTTPClient", "NIOFoundationCompat"]
2728
),
2829
.testTarget(
2930
name: "LambdaSwiftSprinterNioPluginTests",

Sources/LambdaSwiftSprinterNioPlugin/LambdaApiNIO.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Foundation
2020
import LambdaSwiftSprinter
2121
import NIO
2222
import NIOHTTP1
23+
import NIOFoundationCompat
2324

2425
public typealias SprinterNIO = Sprinter<LambdaApiNIO>
2526

@@ -48,9 +49,16 @@ extension HTTPClient: HTTPClientProtocol {
4849

4950
}
5051

52+
/// The `LambdaApiNIO` class implements the LambdaAPI protocol using NIO.
53+
///
5154
public class LambdaApiNIO: LambdaAPI {
55+
5256
let urlBuilder: LambdaRuntimeAPIUrlBuilder
5357

58+
/// Construct a `LambdaApiNIO` class.
59+
///
60+
/// - parameters
61+
/// - awsLambdaRuntimeAPI: AWS_LAMBDA_RUNTIME_API
5462
public required init(awsLambdaRuntimeAPI: String) throws {
5563
self.urlBuilder = try LambdaRuntimeAPIUrlBuilder(awsLambdaRuntimeAPI: awsLambdaRuntimeAPI)
5664
}
@@ -69,8 +77,9 @@ public class LambdaApiNIO: LambdaAPI {
6977
}
7078

7179
if let body = result.body,
72-
let buffer = body.getBytes(at: 0, length: body.readableBytes) {
73-
let data = buffer.data
80+
let data = body.getData(at: 0,
81+
length: body.readableBytes,
82+
byteTransferStrategy: .noCopy) {
7483
return (event: data, responseHeaders: httpHeaders.dictionary)
7584
} else {
7685
throw SprinterNIOError.invalidBuffer

Sources/LambdaSwiftSprinterNioPlugin/Utils.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@
1313
// limitations under the License.
1414

1515
import Foundation
16-
import LambdaSwiftSprinter
1716
import NIO
1817
import NIOHTTP1
19-
20-
internal extension Array where Element == UInt8 {
21-
var data: Data {
22-
return Data(self)
23-
}
24-
}
18+
import NIOFoundationCompat
2519

2620
internal extension HTTPHeaders {
2721
var dictionary: [String: String] {
@@ -39,7 +33,7 @@ internal extension Data {
3933
let jsonEncoder = JSONEncoder()
4034
self = try jsonEncoder.encode(object)
4135
}
42-
36+
4337
var byteBuffer: ByteBuffer {
4438
var buffer = ByteBufferAllocator().buffer(capacity: self.count)
4539
buffer.writeBytes(self)

0 commit comments

Comments
 (0)