@@ -67,8 +67,8 @@ extension Lambda {
67
67
///
68
68
/// It accepts three types of requests from the Lambda function (through the LambdaRuntimeClient):
69
69
/// 1. GET /next - the lambda function polls this endpoint to get the next invocation request
70
- /// 2. POST /:requestID /response - the lambda function posts the response to the invocation request
71
- /// 3. POST /:requestID /error - the lambda function posts an error response to the invocation request
70
+ /// 2. POST /:requestId /response - the lambda function posts the response to the invocation request
71
+ /// 3. POST /:requestId /error - the lambda function posts an error response to the invocation request
72
72
///
73
73
/// It also accepts one type of request from the client invoking the lambda function:
74
74
/// 1. POST /invoke - the client posts the event to the lambda function
@@ -309,22 +309,23 @@ internal struct LambdaHTTPServer {
309
309
}
310
310
311
311
/// This function checks if the request is a streaming response request
312
- /// verb = POST, uri = :requestID /response, HTTP Header contains "Transfer-Encoding: chunked"
312
+ /// verb = POST, uri = :requestId /response, HTTP Header contains "Transfer-Encoding: chunked"
313
313
private func isStreamingResponse( _ requestHead: HTTPRequestHead ) -> Bool {
314
314
requestHead. method == . POST && requestHead. uri. hasSuffix ( Consts . postResponseURLSuffix)
315
315
&& requestHead. headers. contains ( name: " Transfer-Encoding " )
316
- && requestHead. headers [ " Transfer-Encoding " ] . contains ( " chunked " )
316
+ && ( requestHead. headers [ " Transfer-Encoding " ] . contains ( " chunked " )
317
+ || requestHead. headers [ " Transfer-Encoding " ] . contains ( " Chunked " ) )
317
318
}
318
319
319
- /// This function pareses and returns the requestId or nil if the request is malformed
320
+ /// This function parses and returns the requestId or nil if the request doesn't contain a requestId
320
321
private func getRequestId( from head: HTTPRequestHead ) -> String ? {
321
322
let parts = head. uri. split ( separator: " / " )
322
323
return parts. count > 2 ? String ( parts [ parts. count - 2 ] ) : nil
323
324
}
324
325
/// This function process the URI request sent by the client and by the Lambda function
325
326
///
326
327
/// It enqueues the client invocation and iterate over the invocation queue when the Lambda function sends /next request
327
- /// It answers the /:requestID /response and /:requestID /error requests sent by the Lambda function but do not process the body
328
+ /// It answers the /:requestId /response and /:requestId /error requests sent by the Lambda function but do not process the body
328
329
///
329
330
/// - Parameters:
330
331
/// - head: the HTTP request head
@@ -361,13 +362,13 @@ internal struct LambdaHTTPServer {
361
362
}
362
363
// we always accept the /invoke request and push them to the pool
363
364
let requestId = " \( DispatchTime . now ( ) . uptimeNanoseconds) "
364
- logger [ metadataKey: " requestID " ] = " \( requestId) "
365
+ logger [ metadataKey: " requestId " ] = " \( requestId) "
365
366
logger. trace ( " /invoke received invocation, pushing it to the stack " )
366
367
await self . invocationPool. push ( LocalServerInvocation ( requestId: requestId, request: body) )
367
368
368
369
// wait for the lambda function to process the request
369
370
for try await response in self . responsePool {
370
- logger [ metadataKey: " requestID " ] = " \( requestId) "
371
+ logger [ metadataKey: " response requestId " ] = " \( response . requestId ?? " nil " ) "
371
372
logger. trace ( " Received response to return to client " )
372
373
if response. requestId == requestId {
373
374
logger. trace ( " /invoke requestId is valid, sending the response " )
@@ -415,38 +416,38 @@ internal struct LambdaHTTPServer {
415
416
// This should not happen as the async iterator blocks until there is a task to process
416
417
fatalError ( " No more invocations to process - the async for loop should not return " )
417
418
418
- // :requestID /response endpoint is called by the lambda posting the response
419
+ // :requestId /response endpoint is called by the lambda posting the response
419
420
case ( . POST, let url) where url. hasSuffix ( Consts . postResponseURLSuffix) :
420
- guard let requestID = getRequestId ( from: head) else {
421
+ guard let requestId = getRequestId ( from: head) else {
421
422
// the request is malformed, since we were expecting a requestId in the path
422
423
return try await sendResponse ( . init( status: . badRequest) , outbound: outbound, logger: logger)
423
424
}
424
425
// enqueue the lambda function response to be served as response to the client /invoke
425
- logger. trace ( " /:requestID /response received response " , metadata: [ " requestId " : " \( requestID ) " ] )
426
+ logger. trace ( " /:requestId /response received response " , metadata: [ " requestId " : " \( requestId ) " ] )
426
427
await self . responsePool. push (
427
428
LocalServerResponse (
428
- id: requestID ,
429
+ id: requestId ,
429
430
status: . ok,
430
431
headers: HTTPHeaders ( [ ( " Content-Type " , " application/json " ) ] ) ,
431
432
body: body
432
433
)
433
434
)
434
435
435
436
// tell the Lambda function we accepted the response
436
- return try await sendResponse ( . init( id: requestID , status: . accepted) , outbound: outbound, logger: logger)
437
+ return try await sendResponse ( . init( id: requestId , status: . accepted) , outbound: outbound, logger: logger)
437
438
438
- // :requestID /error endpoint is called by the lambda posting an error response
439
- // we accept all requestID and we do not handle the body, we just acknowledge the request
439
+ // :requestId /error endpoint is called by the lambda posting an error response
440
+ // we accept all requestId and we do not handle the body, we just acknowledge the request
440
441
case ( . POST, let url) where url. hasSuffix ( Consts . postErrorURLSuffix) :
441
- guard let requestID = getRequestId ( from: head) else {
442
+ guard let requestId = getRequestId ( from: head) else {
442
443
// the request is malformed, since we were expecting a requestId in the path
443
444
return try await sendResponse ( . init( status: . badRequest) , outbound: outbound, logger: logger)
444
445
}
445
446
// enqueue the lambda function response to be served as response to the client /invoke
446
- logger. trace ( " /:requestID /response received response " , metadata: [ " requestId " : " \( requestID ) " ] )
447
+ logger. trace ( " /:requestId /response received response " , metadata: [ " requestId " : " \( requestId ) " ] )
447
448
await self . responsePool. push (
448
449
LocalServerResponse (
449
- id: requestID ,
450
+ id: requestId ,
450
451
status: . internalServerError,
451
452
headers: HTTPHeaders ( [ ( " Content-Type " , " application/json " ) ] ) ,
452
453
body: body
0 commit comments