@@ -303,7 +303,7 @@ final actor NewLambdaRuntimeClient: LambdaRuntimeClientProtocol {
303
303
NIOHTTPClientResponseAggregator ( maxContentLength: 6 * 1024 * 1024 )
304
304
)
305
305
try channel. pipeline. syncOperations. addHandler (
306
- LambdaChannelHandler ( delegate: self , logger: self . logger)
306
+ LambdaChannelHandler ( delegate: self , logger: self . logger, configuration : self . configuration )
307
307
)
308
308
return channel. eventLoop. makeSucceededFuture ( ( ) )
309
309
} catch {
@@ -433,10 +433,32 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
433
433
private var reusableErrorBuffer : ByteBuffer ?
434
434
private let logger : Logger
435
435
private let delegate : Delegate
436
+ private let configuration : NewLambdaRuntimeClient . Configuration
436
437
437
- init ( delegate: Delegate , logger: Logger ) {
438
+ let defaultHeaders : HTTPHeaders
439
+ /// These headers must be sent along an invocation or initialization error report
440
+ let errorHeaders : HTTPHeaders
441
+ /// These headers must be sent along an invocation or initialization error report
442
+ let streamingHeaders : HTTPHeaders
443
+
444
+ init ( delegate: Delegate , logger: Logger , configuration: NewLambdaRuntimeClient . Configuration ) {
438
445
self . delegate = delegate
439
446
self . logger = logger
447
+ self . configuration = configuration
448
+ self . defaultHeaders = [
449
+ " host " : " \( self . configuration. ip) : \( self . configuration. port) " ,
450
+ " user-agent " : " Swift-Lambda/Unknown " ,
451
+ ]
452
+ self . errorHeaders = [
453
+ " host " : " \( self . configuration. ip) : \( self . configuration. port) " ,
454
+ " user-agent " : " Swift-Lambda/Unknown " ,
455
+ " lambda-runtime-function-error-type " : " Unhandled " ,
456
+ ]
457
+ self . streamingHeaders = [
458
+ " host " : " \( self . configuration. ip) : \( self . configuration. port) " ,
459
+ " user-agent " : " Swift-Lambda/Unknown " ,
460
+ " transfer-encoding " : " streaming " ,
461
+ ]
440
462
}
441
463
442
464
func nextInvocation( isolation: isolated ( any Actor ) ? = #isolation) async throws -> Invocation {
@@ -578,7 +600,7 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
578
600
version: . http1_1,
579
601
method: . POST,
580
602
uri: url,
581
- headers: NewLambdaRuntimeClient . streamingHeaders
603
+ headers: self . streamingHeaders
582
604
)
583
605
584
606
context. write ( self . wrapOutboundOut ( . head( httpRequest) ) , promise: nil )
@@ -604,11 +626,12 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
604
626
let headers : HTTPHeaders =
605
627
if byteBuffer? . readableBytes ?? 0 < 6_000_000 {
606
628
[
629
+ " host " : " \( self . configuration. ip) : \( self . configuration. port) " ,
607
630
" user-agent " : " Swift-Lambda/Unknown " ,
608
631
" content-length " : " \( byteBuffer? . readableBytes ?? 0 ) " ,
609
632
]
610
633
} else {
611
- NewLambdaRuntimeClient . streamingHeaders
634
+ self . streamingHeaders
612
635
}
613
636
614
637
let httpRequest = HTTPRequestHead (
@@ -634,7 +657,7 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
634
657
version: . http1_1,
635
658
method: . GET,
636
659
uri: self . nextInvocationPath,
637
- headers: NewLambdaRuntimeClient . defaultHeaders
660
+ headers: self . defaultHeaders
638
661
)
639
662
640
663
context. write ( self . wrapOutboundOut ( . head( httpRequest) ) , promise: nil )
@@ -650,7 +673,7 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
650
673
version: . http1_1,
651
674
method: . POST,
652
675
uri: url,
653
- headers: NewLambdaRuntimeClient . errorHeaders
676
+ headers: self . errorHeaders
654
677
)
655
678
656
679
if self . reusableErrorBuffer == nil {
@@ -797,22 +820,3 @@ extension LambdaChannelHandler: ChannelInboundHandler {
797
820
context. fireChannelInactive ( )
798
821
}
799
822
}
800
-
801
- extension NewLambdaRuntimeClient {
802
- static let defaultHeaders : HTTPHeaders = [
803
- " user-agent " : " Swift-Lambda/Unknown "
804
- ]
805
-
806
- /// These headers must be sent along an invocation or initialization error report
807
- static let errorHeaders : HTTPHeaders = [
808
- " user-agent " : " Swift-Lambda/Unknown " ,
809
- " lambda-runtime-function-error-type " : " Unhandled " ,
810
- ]
811
-
812
- /// These headers must be sent along an invocation or initialization error report
813
- static let streamingHeaders : HTTPHeaders = [
814
- " user-agent " : " Swift-Lambda/Unknown " ,
815
- " transfer-encoding " : " streaming " ,
816
- ]
817
-
818
- }
0 commit comments