@@ -358,7 +358,11 @@ internal struct LambdaHTTPServer {
358358 // client POST /invoke
359359 case ( . POST, let url) where url. hasSuffix ( self . invocationEndpoint) :
360360 guard let body else {
361- return try await sendResponse ( . init( status: . badRequest) , outbound: outbound, logger: logger)
361+ return try await sendResponse (
362+ . init( status: . badRequest, final: true ) ,
363+ outbound: outbound,
364+ logger: logger
365+ )
362366 }
363367 // we always accept the /invoke request and push them to the pool
364368 let requestId = " \( DispatchTime . now ( ) . uptimeNanoseconds) "
@@ -394,7 +398,11 @@ internal struct LambdaHTTPServer {
394398
395399 // client uses incorrect HTTP method
396400 case ( _, let url) where url. hasSuffix ( self . invocationEndpoint) :
397- return try await sendResponse ( . init( status: . methodNotAllowed) , outbound: outbound, logger: logger)
401+ return try await sendResponse (
402+ . init( status: . methodNotAllowed, final: true ) ,
403+ outbound: outbound,
404+ logger: logger
405+ )
398406
399407 //
400408 // lambda invocations
@@ -420,7 +428,11 @@ internal struct LambdaHTTPServer {
420428 case ( . POST, let url) where url. hasSuffix ( Consts . postResponseURLSuffix) :
421429 guard let requestId = getRequestId ( from: head) else {
422430 // the request is malformed, since we were expecting a requestId in the path
423- return try await sendResponse ( . init( status: . badRequest) , outbound: outbound, logger: logger)
431+ return try await sendResponse (
432+ . init( status: . badRequest, final: true ) ,
433+ outbound: outbound,
434+ logger: logger
435+ )
424436 }
425437 // enqueue the lambda function response to be served as response to the client /invoke
426438 logger. trace ( " /:requestId/response received response " , metadata: [ " requestId " : " \( requestId) " ] )
@@ -435,14 +447,22 @@ internal struct LambdaHTTPServer {
435447 )
436448
437449 // tell the Lambda function we accepted the response
438- return try await sendResponse ( . init( id: requestId, status: . accepted, final: true ) , outbound: outbound, logger: logger)
450+ return try await sendResponse (
451+ . init( id: requestId, status: . accepted, final: true ) ,
452+ outbound: outbound,
453+ logger: logger
454+ )
439455
440456 // :requestId/error endpoint is called by the lambda posting an error response
441457 // we accept all requestId and we do not handle the body, we just acknowledge the request
442458 case ( . POST, let url) where url. hasSuffix ( Consts . postErrorURLSuffix) :
443459 guard let requestId = getRequestId ( from: head) else {
444460 // the request is malformed, since we were expecting a requestId in the path
445- return try await sendResponse ( . init( status: . badRequest) , outbound: outbound, logger: logger)
461+ return try await sendResponse (
462+ . init( status: . badRequest, final: true ) ,
463+ outbound: outbound,
464+ logger: logger
465+ )
446466 }
447467 // enqueue the lambda function response to be served as response to the client /invoke
448468 logger. trace ( " /:requestId/response received response " , metadata: [ " requestId " : " \( requestId) " ] )
@@ -451,15 +471,16 @@ internal struct LambdaHTTPServer {
451471 id: requestId,
452472 status: . internalServerError,
453473 headers: HTTPHeaders ( [ ( " Content-Type " , " application/json " ) ] ) ,
454- body: body
474+ body: body,
475+ final: true
455476 )
456477 )
457478
458- return try await sendResponse ( . init( status: . accepted) , outbound: outbound, logger: logger)
479+ return try await sendResponse ( . init( status: . accepted, final : true ) , outbound: outbound, logger: logger)
459480
460481 // unknown call
461482 default :
462- return try await sendResponse ( . init( status: . notFound) , outbound: outbound, logger: logger)
483+ return try await sendResponse ( . init( status: . notFound, final : true ) , outbound: outbound, logger: logger)
463484 }
464485 }
465486
0 commit comments