Skip to content

Commit e1c374e

Browse files
committed
Merge branch 'develop' into main
2 parents 84422db + 786a4d7 commit e1c374e

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

Package.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ let package = Package(
66

77
name: "MacroLambda",
88

9-
platforms : [ .macOS(.v10_13) ], // drop once #152 is fixed in the runtime
10-
119
products: [
1210
.library(name: "MacroLambdaCore", targets: [ "MacroLambdaCore" ]),
1311
.library(name: "MacroLambda", targets: [ "MacroLambda" ])
@@ -19,7 +17,7 @@ let package = Package(
1917
.package(url: "https://github.com/Macro-swift/MacroExpress.git",
2018
from: "0.8.4"),
2119
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
22-
.upToNextMajor(from:"0.3.0"))
20+
.upToNextMajor(from:"0.4.0"))
2321
],
2422

2523
targets: [

Sources/MacroLambdaCore/LambdaNIOConversions.swift

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MacroLambda
44
//
55
// Created by Helge Heß
6-
// Copyright © 2020 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2021 ZeeZide GmbH. All rights reserved.
77
//
88

99
#if canImport(AWSLambdaEvents)
@@ -73,16 +73,15 @@ internal extension AWSLambdaEvents.HTTPMultiValueHeaders {
7373
internal extension NIOHTTP1.HTTPHeaders {
7474

7575
@inlinable
76-
func asLambda() -> ( single : AWSLambdaEvents.HTTPHeaders?,
77-
multi : AWSLambdaEvents.HTTPMultiValueHeaders?,
76+
func asLambda() -> ( headers : AWSLambdaEvents.HTTPHeaders?,
7877
cookies : [ String ]? )
7978
{
80-
guard !isEmpty else { return ( nil, nil, nil ) }
79+
guard !isEmpty else { return ( nil, nil ) }
8180

8281
// Those do no proper CI, lets hope they are consistent
83-
var single = AWSLambdaEvents.HTTPHeaders()
84-
var multi = AWSLambdaEvents.HTTPMultiValueHeaders()
82+
var headers = AWSLambdaEvents.HTTPHeaders()
8583
var cookies = [ String ]()
84+
headers.reserveCapacity(headers.count)
8685

8786
// Schnüff, we don't get NIO's `compareCaseInsensitiveASCIIBytes`
8887
for ( name, value ) in self {
@@ -93,22 +92,20 @@ internal extension NIOHTTP1.HTTPHeaders {
9392
cookies.append(value)
9493
}
9594
else {
96-
if let other = single.removeValue(forKey: name) {
97-
assert(multi[name] == nil)
98-
multi[name] = [ other, value ]
99-
}
100-
else if var values = multi.removeValue(forKey: name) {
101-
values.append(value)
102-
multi[name] = values
95+
if let existing = headers.removeValue(forKey: name) {
96+
// Don't know, SwiftLambda 0.4 dropped the multiheaders? What should
97+
// we do for dupes?
98+
if value .isEmpty {}
99+
else if existing.isEmpty { headers[name] = value }
100+
else { headers[name] = existing + ", " + value }
103101
}
104102
else {
105-
single[name] = value
103+
headers[name] = value
106104
}
107105
}
108106
}
109107

110-
return ( single : single .isEmpty ? nil : single,
111-
multi : multi .isEmpty ? nil : multi,
108+
return ( headers : headers.isEmpty ? nil : headers,
112109
cookies : cookies.isEmpty ? nil : cookies )
113110
}
114111
}

Sources/MacroLambdaCore/LambdaResponse.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
// MacroLambda
44
//
55
// Created by Helge Heß
6-
// Copyright © 2020 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2021 ZeeZide GmbH. All rights reserved.
77
//
88

99
#if canImport(AWSLambdaEvents)
10-
11-
import class http.ServerResponse
1210
import enum AWSLambdaEvents.APIGateway
11+
import class http.ServerResponse
1312

1413
extension ServerResponse {
1514

1615
var asLambdaGatewayResponse: APIGateway.V2.Response {
1716
assert(writableEnded, "sending ServerResponse which didn't end?!")
1817

19-
let ( singleHeaders, multiHeaders, cookies ) = headers.asLambda()
18+
let ( headers, cookies ) = self.headers.asLambda()
2019

2120
let body : String? = {
2221
guard let writtenContent = writableBuffer, !writtenContent.isEmpty else {
@@ -35,12 +34,11 @@ extension ServerResponse {
3534
}
3635
}()
3736

38-
return .init(statusCode : status.asLambda,
39-
headers : singleHeaders,
40-
multiValueHeaders : multiHeaders,
41-
body : body,
42-
isBase64Encoded : body != nil ? true : false,
43-
cookies : cookies)
37+
return .init(statusCode : status.asLambda,
38+
headers : headers,
39+
body : body,
40+
isBase64Encoded : body != nil ? true : false,
41+
cookies : cookies)
4442
}
4543
}
4644

0 commit comments

Comments
 (0)