@@ -248,36 +248,22 @@ internal struct LambdaHTTPServer {
248
248
requestHead = head
249
249
250
250
case . body( let body) :
251
- precondition ( requestHead != nil , " Received .body without .head " )
252
-
253
- // if this is a request from a Streaming Lambda Handler,
254
- // stream the response instead of buffering it
255
- if self . isStreamingResponse ( requestHead) {
256
- // we are receiving a chunked body,
257
- // we can stream the response and not accumulate the chunks
258
- print ( String ( buffer: body) )
259
- } else {
260
- requestBody. setOrWriteImmutableBuffer ( body)
261
- }
251
+ requestBody. setOrWriteImmutableBuffer ( body)
262
252
263
253
case . end:
264
254
precondition ( requestHead != nil , " Received .end without .head " )
265
-
266
- // process the buffered response for non streaming requests
267
- if !self . isStreamingResponse ( requestHead) {
268
- // process the complete request
269
- let response = try await self . processCompleteRequest (
270
- head: requestHead,
271
- body: requestBody,
272
- logger: logger
273
- )
274
- // send the responses
275
- try await self . sendCompleteResponse (
276
- response: response,
277
- outbound: outbound,
278
- logger: logger
279
- )
280
- }
255
+ // process the request
256
+ let response = try await self . processRequest (
257
+ head: requestHead,
258
+ body: requestBody,
259
+ logger: logger
260
+ )
261
+ // send the responses
262
+ try await self . sendResponse (
263
+ response: response,
264
+ outbound: outbound,
265
+ logger: logger
266
+ )
281
267
282
268
requestHead = nil
283
269
requestBody = nil
@@ -295,15 +281,6 @@ internal struct LambdaHTTPServer {
295
281
}
296
282
}
297
283
298
- /// This function checks if the request is a streaming response request
299
- /// verb = POST, uri = :requestID/response, HTTP Header contains "Transfer-Encoding: chunked"
300
- private func isStreamingResponse( _ requestHead: HTTPRequestHead ) -> Bool {
301
- requestHead. method == . POST &&
302
- requestHead. uri. hasSuffix ( Consts . postResponseURLSuffix) &&
303
- requestHead. headers. contains ( name: " Transfer-Encoding " ) &&
304
- requestHead. headers [ " Transfer-Encoding " ] . contains ( " chunked " )
305
- }
306
-
307
284
/// This function process the URI request sent by the client and by the Lambda function
308
285
///
309
286
/// It enqueues the client invocation and iterate over the invocation queue when the Lambda function sends /next request
@@ -314,7 +291,7 @@ internal struct LambdaHTTPServer {
314
291
/// - body: the HTTP request body
315
292
/// - Throws:
316
293
/// - Returns: the response to send back to the client or the Lambda function
317
- private func processCompleteRequest (
294
+ private func processRequest (
318
295
head: HTTPRequestHead ,
319
296
body: ByteBuffer ? ,
320
297
logger: Logger
@@ -437,7 +414,7 @@ internal struct LambdaHTTPServer {
437
414
}
438
415
}
439
416
440
- private func sendCompleteResponse (
417
+ private func sendResponse (
441
418
response: LocalServerResponse ,
442
419
outbound: NIOAsyncChannelOutboundWriter < HTTPServerResponsePart > ,
443
420
logger: Logger
0 commit comments