@@ -274,7 +274,7 @@ internal struct LambdaHTTPServer {
274
274
275
275
case . end:
276
276
precondition ( requestHead != nil , " Received .end without .head " )
277
-
277
+
278
278
// process the buffered response for non streaming requests
279
279
if !self . isStreamingResponse ( requestHead) {
280
280
// process the request and send the response
@@ -288,7 +288,7 @@ internal struct LambdaHTTPServer {
288
288
await self . responsePool. push (
289
289
LocalServerResponse ( id: requestId, final: true )
290
290
)
291
-
291
+
292
292
}
293
293
294
294
requestHead = nil
@@ -311,16 +311,15 @@ internal struct LambdaHTTPServer {
311
311
/// This function checks if the request is a streaming response request
312
312
/// verb = POST, uri = :requestID/response, HTTP Header contains "Transfer-Encoding: chunked"
313
313
private func isStreamingResponse( _ requestHead: HTTPRequestHead ) -> Bool {
314
- requestHead. method == . POST &&
315
- requestHead. uri. hasSuffix ( Consts . postResponseURLSuffix) &&
316
- requestHead. headers. contains ( name: " Transfer-Encoding " ) &&
317
- requestHead. headers [ " Transfer-Encoding " ] . contains ( " chunked " )
314
+ requestHead. method == . POST && requestHead. uri. hasSuffix ( Consts . postResponseURLSuffix)
315
+ && requestHead. headers. contains ( name: " Transfer-Encoding " )
316
+ && requestHead. headers [ " Transfer-Encoding " ] . contains ( " chunked " )
318
317
}
319
318
320
319
/// This function pareses and returns the requestId or nil if the request is malformed
321
320
private func getRequestId( from head: HTTPRequestHead ) -> String ? {
322
- let parts = head. uri. split ( separator: " / " )
323
- return parts. count > 2 ? String ( parts [ parts. count - 2 ] ) : nil
321
+ let parts = head. uri. split ( separator: " / " )
322
+ return parts. count > 2 ? String ( parts [ parts. count - 2 ] ) : nil
324
323
}
325
324
/// This function process the URI request sent by the client and by the Lambda function
326
325
///
@@ -378,7 +377,7 @@ internal struct LambdaHTTPServer {
378
377
try await self . sendResponse ( response, outbound: outbound, logger: logger)
379
378
if response. final == true {
380
379
logger. trace ( " /invoke returning " )
381
- return // if the response is final, we can return and close the connection
380
+ return // if the response is final, we can return and close the connection
382
381
}
383
382
} else {
384
383
logger. error (
@@ -497,7 +496,7 @@ internal struct LambdaHTTPServer {
497
496
if response. final {
498
497
logger. trace ( " Sending end " )
499
498
try await outbound. write ( HTTPServerResponsePart . end ( nil ) )
500
- }
499
+ }
501
500
}
502
501
503
502
/// A shared data structure to store the current invocation or response requests and the continuation objects.
@@ -585,7 +584,13 @@ internal struct LambdaHTTPServer {
585
584
let headers : HTTPHeaders ?
586
585
let body : ByteBuffer ?
587
586
let final : Bool
588
- init ( id: String ? = nil , status: HTTPResponseStatus ? = nil , headers: HTTPHeaders ? = nil , body: ByteBuffer ? = nil , final: Bool = false ) {
587
+ init (
588
+ id: String ? = nil ,
589
+ status: HTTPResponseStatus ? = nil ,
590
+ headers: HTTPHeaders ? = nil ,
591
+ body: ByteBuffer ? = nil ,
592
+ final: Bool = false
593
+ ) {
589
594
self . requestId = id
590
595
self . status = status
591
596
self . headers = headers
@@ -604,14 +609,20 @@ internal struct LambdaHTTPServer {
604
609
let headers = HTTPHeaders ( [
605
610
( AmazonHeaders . requestID, self . requestId) ,
606
611
(
607
- AmazonHeaders . invokedFunctionARN,
608
- " arn:aws:lambda:us-east-1: \( Int16 . random ( in: Int16 . min ... Int16 . max) ) :function:custom-runtime "
612
+ AmazonHeaders . invokedFunctionARN,
613
+ " arn:aws:lambda:us-east-1: \( Int16 . random ( in: Int16 . min ... Int16 . max) ) :function:custom-runtime "
609
614
) ,
610
615
( AmazonHeaders . traceID, " Root= \( AmazonHeaders . generateXRayTraceID ( ) ) ;Sampled=1 " ) ,
611
616
( AmazonHeaders . deadline, " \( DispatchWallTime . distantFuture. millisSinceEpoch) " ) ,
612
617
] )
613
618
614
- return LocalServerResponse ( id: self . requestId, status: . accepted, headers: headers, body: self . request, final: true )
619
+ return LocalServerResponse (
620
+ id: self . requestId,
621
+ status: . accepted,
622
+ headers: headers,
623
+ body: self . request,
624
+ final: true
625
+ )
615
626
}
616
627
}
617
628
}
0 commit comments