Skip to content

Commit f33ecaa

Browse files
committed
write requestId with lowercase d
1 parent 2b1cae5 commit f33ecaa

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Sources/AWSLambdaRuntime/Lambda+LocalServer.swift

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ extension Lambda {
6767
///
6868
/// It accepts three types of requests from the Lambda function (through the LambdaRuntimeClient):
6969
/// 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
7272
///
7373
/// It also accepts one type of request from the client invoking the lambda function:
7474
/// 1. POST /invoke - the client posts the event to the lambda function
@@ -309,22 +309,23 @@ internal struct LambdaHTTPServer {
309309
}
310310

311311
/// 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"
313313
private func isStreamingResponse(_ requestHead: HTTPRequestHead) -> Bool {
314314
requestHead.method == .POST && requestHead.uri.hasSuffix(Consts.postResponseURLSuffix)
315315
&& 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"))
317318
}
318319

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
320321
private func getRequestId(from head: HTTPRequestHead) -> String? {
321322
let parts = head.uri.split(separator: "/")
322323
return parts.count > 2 ? String(parts[parts.count - 2]) : nil
323324
}
324325
/// This function process the URI request sent by the client and by the Lambda function
325326
///
326327
/// 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
328329
///
329330
/// - Parameters:
330331
/// - head: the HTTP request head
@@ -361,13 +362,13 @@ internal struct LambdaHTTPServer {
361362
}
362363
// we always accept the /invoke request and push them to the pool
363364
let requestId = "\(DispatchTime.now().uptimeNanoseconds)"
364-
logger[metadataKey: "requestID"] = "\(requestId)"
365+
logger[metadataKey: "requestId"] = "\(requestId)"
365366
logger.trace("/invoke received invocation, pushing it to the stack")
366367
await self.invocationPool.push(LocalServerInvocation(requestId: requestId, request: body))
367368

368369
// wait for the lambda function to process the request
369370
for try await response in self.responsePool {
370-
logger[metadataKey: "requestID"] = "\(requestId)"
371+
logger[metadataKey: "response requestId"] = "\(response.requestId ?? "nil")"
371372
logger.trace("Received response to return to client")
372373
if response.requestId == requestId {
373374
logger.trace("/invoke requestId is valid, sending the response")
@@ -415,38 +416,38 @@ internal struct LambdaHTTPServer {
415416
// This should not happen as the async iterator blocks until there is a task to process
416417
fatalError("No more invocations to process - the async for loop should not return")
417418

418-
// :requestID/response endpoint is called by the lambda posting the response
419+
// :requestId/response endpoint is called by the lambda posting the response
419420
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 {
421422
// the request is malformed, since we were expecting a requestId in the path
422423
return try await sendResponse(.init(status: .badRequest), outbound: outbound, logger: logger)
423424
}
424425
// 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)"])
426427
await self.responsePool.push(
427428
LocalServerResponse(
428-
id: requestID,
429+
id: requestId,
429430
status: .ok,
430431
headers: HTTPHeaders([("Content-Type", "application/json")]),
431432
body: body
432433
)
433434
)
434435

435436
// 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)
437438

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
440441
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 {
442443
// the request is malformed, since we were expecting a requestId in the path
443444
return try await sendResponse(.init(status: .badRequest), outbound: outbound, logger: logger)
444445
}
445446
// 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)"])
447448
await self.responsePool.push(
448449
LocalServerResponse(
449-
id: requestID,
450+
id: requestId,
450451
status: .internalServerError,
451452
headers: HTTPHeaders([("Content-Type", "application/json")]),
452453
body: body

0 commit comments

Comments
 (0)