Skip to content

Commit d4fd562

Browse files
committed
continued
1 parent 19590e4 commit d4fd562

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Sources/AWSLambdaRuntime/LambdaRuntimeClient.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
238238
guard case .sentResponse(requestID) = self.lambdaState else {
239239
fatalError("Invalid state: \(self.lambdaState)")
240240
}
241-
try await handler.finishResponseRequest(finalData: buffer, requestID: requestID)
241+
try await handler.finishResponseRequest(userHeaders: self.userHeaders, finalData: buffer, requestID: requestID)
242242
guard case .sentResponse(requestID) = self.lambdaState else {
243243
fatalError("Invalid state: \(self.lambdaState)")
244244
}
@@ -496,9 +496,11 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
496496
"lambda-runtime-function-error-type": "Unhandled",
497497
]
498498
self.streamingHeaders = [
499-
"host": "\(self.configuration.ip):\(self.configuration.port)",
499+
"Host": "\(self.configuration.ip):\(self.configuration.port)",
500500
"user-agent": .userAgent,
501-
"transfer-encoding": "chunked",
501+
// "Content-type": "application/vnd.awslambda.http-integration-response",
502+
// "Transfer-encoding": "chunked",
503+
// "Lambda-Runtime-Function-Response-Mode": "streaming",
502504
]
503505
}
504506

@@ -596,6 +598,7 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
596598

597599
func finishResponseRequest(
598600
isolation: isolated (any Actor)? = #isolation,
601+
userHeaders: HTTPHeaders,
599602
finalData: ByteBuffer?,
600603
requestID: String
601604
) async throws {
@@ -607,13 +610,13 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
607610
case .connected(let context, .waitingForResponse):
608611
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
609612
self.state = .connected(context, .sentResponse(continuation))
610-
self.sendResponseFinish(finalData, sendHeadWithRequestID: requestID, context: context)
613+
self.sendResponseFinish(userHeaders, finalData, sendHeadWithRequestID: requestID, context: context)
611614
}
612615

613616
case .connected(let context, .sendingResponse):
614617
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
615618
self.state = .connected(context, .sentResponse(continuation))
616-
self.sendResponseFinish(finalData, sendHeadWithRequestID: nil, context: context)
619+
self.sendResponseFinish(userHeaders, finalData, sendHeadWithRequestID: nil, context: context)
617620
}
618621

619622
case .connected(_, .sentResponse):
@@ -639,14 +642,15 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
639642
// TODO: This feels super expensive. We should be able to make this cheaper. requestIDs are fixed length
640643
let url = Consts.invocationURLPrefix + "/" + requestID + Consts.postResponseURLSuffix
641644

642-
var responseHeaders = self.streamingHeaders
643-
responseHeaders.add(contentsOf: userHeaders)
644-
logger.trace("sendResponseBodyPart : ========== Sending response headers: \(responseHeaders)")
645+
var headers = HTTPHeaders()
646+
headers.add(contentsOf: userHeaders)
647+
headers.add(contentsOf: self.streamingHeaders)
648+
logger.trace("sendResponseBodyPart : ========== Sending response headers: \(headers)")
645649
let httpRequest = HTTPRequestHead(
646650
version: .http1_1,
647651
method: .POST,
648652
uri: url,
649-
headers: responseHeaders
653+
headers: headers // FIXME these are the headers returned to the control plane. I'm not sure if we should use the streaming headers here
650654
)
651655

652656
context.write(self.wrapOutboundOut(.head(httpRequest)), promise: nil)
@@ -659,6 +663,7 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
659663

660664
private func sendResponseFinish(
661665
isolation: isolated (any Actor)? = #isolation,
666+
_ userHeaders: HTTPHeaders,
662667
_ byteBuffer: ByteBuffer?,
663668
sendHeadWithRequestID: String?,
664669
context: ChannelHandlerContext
@@ -669,7 +674,7 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
669674

670675
// If we have less than 6MB, we don't want to use the streaming API. If we have more
671676
// than 6MB we must use the streaming mode.
672-
let headers: HTTPHeaders =
677+
var headers: HTTPHeaders =
673678
if byteBuffer?.readableBytes ?? 0 < 6_000_000 {
674679
[
675680
"host": "\(self.configuration.ip):\(self.configuration.port)",
@@ -679,7 +684,7 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
679684
} else {
680685
self.streamingHeaders
681686
}
682-
687+
headers.add(contentsOf: userHeaders)
683688
logger.trace("sendResponseFinish : ========== Sending response headers: \(headers)")
684689
let httpRequest = HTTPRequestHead(
685690
version: .http1_1,

0 commit comments

Comments
 (0)