Skip to content

Commit 03876f6

Browse files
authored
[TestServer] Fix 488 and add simple test lambda (#489)
Fixes: #488
1 parent 61cd5d5 commit 03876f6

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift

+17-6
Original file line numberDiff line numberDiff line change
@@ -352,33 +352,44 @@ private struct LambdaHTTPServer {
352352
// :requestID/response endpoint is called by the lambda posting the response
353353
case (.POST, let url) where url.hasSuffix(Consts.postResponseURLSuffix):
354354
let parts = head.uri.split(separator: "/")
355-
guard let requestId = parts.count > 2 ? String(parts[parts.count - 2]) : nil else {
355+
guard let requestID = parts.count > 2 ? String(parts[parts.count - 2]) : nil else {
356356
// the request is malformed, since we were expecting a requestId in the path
357357
return .init(status: .badRequest)
358358
}
359359
// enqueue the lambda function response to be served as response to the client /invoke
360-
logger.trace("/:requestID/response received response", metadata: ["requestId": "\(requestId)"])
360+
logger.trace("/:requestID/response received response", metadata: ["requestId": "\(requestID)"])
361361
await self.responsePool.push(
362362
LocalServerResponse(
363-
id: requestId,
363+
id: requestID,
364364
status: .ok,
365365
headers: [("Content-Type", "application/json")],
366366
body: body
367367
)
368368
)
369369

370370
// tell the Lambda function we accepted the response
371-
return .init(id: requestId, status: .accepted)
371+
return .init(id: requestID, status: .accepted)
372372

373373
// :requestID/error endpoint is called by the lambda posting an error response
374374
// we accept all requestID and we do not handle the body, we just acknowledge the request
375375
case (.POST, let url) where url.hasSuffix(Consts.postErrorURLSuffix):
376376
let parts = head.uri.split(separator: "/")
377-
guard let _ = parts.count > 2 ? String(parts[parts.count - 2]) : nil else {
377+
guard let requestID = parts.count > 2 ? String(parts[parts.count - 2]) : nil else {
378378
// the request is malformed, since we were expecting a requestId in the path
379379
return .init(status: .badRequest)
380380
}
381-
return .init(status: .ok)
381+
// enqueue the lambda function response to be served as response to the client /invoke
382+
logger.trace("/:requestID/response received response", metadata: ["requestId": "\(requestID)"])
383+
await self.responsePool.push(
384+
LocalServerResponse(
385+
id: requestID,
386+
status: .internalServerError,
387+
headers: [("Content-Type", "application/json")],
388+
body: body
389+
)
390+
)
391+
392+
return .init(status: .accepted)
382393

383394
// unknown call
384395
default:

0 commit comments

Comments
 (0)