@@ -90,37 +90,45 @@ struct LambdaRuntimeClientTests {
9090 }
9191 }
9292
93- @Test
94- func testStreamingResponseHeaders( ) async throws {
95- struct StreamingBehavior : LambdaServerBehavior {
96- let requestId = UUID ( ) . uuidString
97- let event = " hello "
93+ struct StreamingBehavior : LambdaServerBehavior {
94+ let requestId = UUID ( ) . uuidString
95+ let event = " hello "
96+ let customHeaders : Bool
9897
99- func getInvocation ( ) -> GetInvocationResult {
100- . success ( ( self . requestId , self . event ) )
101- }
98+ init ( customHeaders : Bool = false ) {
99+ self . customHeaders = customHeaders
100+ }
102101
103- func processResponse( requestId: String , response: String ? ) -> Result < Void , ProcessResponseError > {
104- #expect( self . requestId == requestId)
105- return . success( ( ) )
106- }
102+ func getInvocation( ) -> GetInvocationResult {
103+ . success( ( self . requestId, self . event) )
104+ }
107105
108- mutating func captureHeaders( _ headers: HTTPHeaders ) {
106+ func processResponse( requestId: String , response: String ? ) -> Result < Void , ProcessResponseError > {
107+ #expect( self . requestId == requestId)
108+ return . success( ( ) )
109+ }
110+
111+ mutating func captureHeaders( _ headers: HTTPHeaders ) {
112+ if customHeaders {
109113 #expect( headers [ " Content-Type " ] . first == " application/vnd.awslambda.http-integration-response " )
110- #expect( headers [ " Lambda-Runtime-Function-Response-Mode " ] . first == " streaming " )
111- #expect( headers [ " Trailer " ] . first? . contains ( " Lambda-Runtime-Function-Error-Type " ) == true )
112114 }
115+ #expect( headers [ " Lambda-Runtime-Function-Response-Mode " ] . first == " streaming " )
116+ #expect( headers [ " Trailer " ] . first? . contains ( " Lambda-Runtime-Function-Error-Type " ) == true )
117+ }
113118
114- func processError( requestId: String , error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
115- Issue . record ( " should not report error " )
116- return . failure( . internalServerError)
117- }
119+ func processError( requestId: String , error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
120+ Issue . record ( " should not report error " )
121+ return . failure( . internalServerError)
122+ }
118123
119- func processInitError( error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
120- Issue . record ( " should not report init error " )
121- return . failure( . internalServerError)
122- }
124+ func processInitError( error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
125+ Issue . record ( " should not report init error " )
126+ return . failure( . internalServerError)
123127 }
128+ }
129+
130+ @Test
131+ func testStreamingResponseHeaders( ) async throws {
124132
125133 let behavior = StreamingBehavior ( )
126134 try await withMockServer ( behaviour: behavior) { port in
@@ -145,6 +153,41 @@ struct LambdaRuntimeClientTests {
145153 }
146154 }
147155
156+ @Test
157+ func testStreamingResponseHeadersWithCustomStatus( ) async throws {
158+
159+ let behavior = StreamingBehavior ( customHeaders: true )
160+ try await withMockServer ( behaviour: behavior) { port in
161+ let configuration = LambdaRuntimeClient . Configuration ( ip: " 127.0.0.1 " , port: port)
162+
163+ try await LambdaRuntimeClient . withRuntimeClient (
164+ configuration: configuration,
165+ eventLoop: NIOSingletons . posixEventLoopGroup. next ( ) ,
166+ logger: self . logger
167+ ) { runtimeClient in
168+ let ( _, writer) = try await runtimeClient. nextInvocation ( )
169+
170+ try await writer. writeStatusAndHeaders (
171+ StreamingLambdaStatusAndHeadersResponse (
172+ statusCode: 418 , // I'm a tea pot
173+ headers: [
174+ " Content-Type " : " text/plain " ,
175+ " x-my-custom-header " : " streaming-example " ,
176+ ]
177+ )
178+ )
179+ // Start streaming response
180+ try await writer. write ( ByteBuffer ( string: " streaming " ) )
181+
182+ // Complete the response
183+ try await writer. finish ( )
184+
185+ // Verify headers were set correctly for streaming mode
186+ // this is done in the behavior's captureHeaders method
187+ }
188+ }
189+ }
190+
148191 @Test
149192 func testCancellation( ) async throws {
150193 struct HappyBehavior : LambdaServerBehavior {
0 commit comments