Skip to content

Commit

Permalink
Update for swift-aws-lambda-events v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed May 24, 2024
1 parent c1baaf1 commit 7b1bf61
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha.1"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "0.1.0"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "0.3.0"),
.package(url: "https://github.com/swift-extras/swift-extras-base64.git", from: "1.0.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-beta.1"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
Expand Down
4 changes: 2 additions & 2 deletions Sources/HummingbirdLambda/APIGatewayV2Lambda.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension APIGatewayV2Request: APIRequest {
return context.http.path
}

var httpMethod: AWSLambdaEvents.HTTPMethod { context.http.method }
var httpMethod: HTTPRequest.Method { context.http.method }
var queryString: String { self.rawQueryString }
var httpHeaders: [(name: String, value: String)] {
self.headers.flatMap { header in
Expand All @@ -77,7 +77,7 @@ extension APIGatewayV2Request: APIRequest {
// conform `APIGatewayV2Response` to `APIResponse` so we can use Response.apiReponse()
extension APIGatewayV2Response: APIResponse {
package init(
statusCode: AWSLambdaEvents.HTTPResponseStatus,
statusCode: HTTPResponse.Status,
headers: AWSLambdaEvents.HTTPHeaders?,
multiValueHeaders: HTTPMultiValueHeaders?,
body: String?,
Expand Down
8 changes: 2 additions & 6 deletions Sources/HummingbirdLambda/Request+APIGateway.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import NIOCore

protocol APIRequest {
var path: String { get }
var httpMethod: AWSLambdaEvents.HTTPMethod { get }
var httpMethod: HTTPRequest.Method { get }
var queryString: String { get }
var httpHeaders: [(name: String, value: String)] { get }
var body: String? { get }
Expand All @@ -36,10 +36,6 @@ extension Request {
return string.addingPercentEncoding(withAllowedCharacters: .urlQueryComponentAllowed) ?? string
}

guard let method = HTTPRequest.Method(from.httpMethod.rawValue) else {
throw HTTPError(.badRequest)
}

// construct URI with query parameters
var uri = from.path
if from.queryString.count > 0 {
Expand All @@ -64,7 +60,7 @@ extension Request {

self.init(
head: .init(
method: method,
method: from.httpMethod,
scheme: "https",
authority: authority,
path: uri,
Expand Down
4 changes: 2 additions & 2 deletions Sources/HummingbirdLambda/Response+APIGateway.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import NIOHTTP1

package protocol APIResponse {
init(
statusCode: AWSLambdaEvents.HTTPResponseStatus,
statusCode: HTTPResponse.Status,
headers: AWSLambdaEvents.HTTPHeaders?,
multiValueHeaders: HTTPMultiValueHeaders?,
body: String?,
Expand Down Expand Up @@ -72,7 +72,7 @@ extension Response {
}

return .init(
statusCode: AWSLambdaEvents.HTTPResponseStatus(code: UInt(self.status.code)),
statusCode: self.status,
headers: singleHeaders,
multiValueHeaders: multiHeaders,
body: body,
Expand Down
5 changes: 3 additions & 2 deletions Tests/HummingbirdLambdaTests/LambdaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ final class LambdaTests: XCTestCase {
}
try await HelloLambda.test { client in
try await client.execute(uri: "/", method: .post) { response in
let expectedBody = "{\"error\":{\"message\":\"\(HelloLambda.body)\"}}\n"
XCTAssertEqual(response.statusCode, .badRequest)
XCTAssertEqual(response.body, HelloLambda.body)
XCTAssertEqual(response.headers?["Content-Length"], HelloLambda.body.utf8.count.description)
XCTAssertEqual(response.body, expectedBody)
XCTAssertEqual(response.headers?["Content-Length"], expectedBody.utf8.count.description)
}
}
}
Expand Down

0 comments on commit 7b1bf61

Please sign in to comment.