@jaypie/express 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1261,6 +1261,9 @@ var cors_helper = (config) => {
1261
1261
  else {
1262
1262
  // Fallback for non-CorsError errors
1263
1263
  res.status(HTTP_CODE_NO_CONTENT);
1264
+ if (typeof res.flushHeaders === "function") {
1265
+ res.flushHeaders();
1266
+ }
1264
1267
  res.end();
1265
1268
  }
1266
1269
  return;
@@ -1290,8 +1293,14 @@ var cors_helper = (config) => {
1290
1293
  // Send 204 No Content response and terminate immediately
1291
1294
  // This is critical for Lambda streaming - we must end the response
1292
1295
  // synchronously to prevent the stream from hanging.
1296
+ // CRITICAL: Flush headers first to initialize the Lambda stream wrapper.
1297
+ // Without this, _wrappedStream may be null when _final() is called,
1298
+ // causing the Lambda response stream to never close.
1293
1299
  res.statusCode = HTTP_CODE_NO_CONTENT;
1294
1300
  res.setHeader("Content-Length", "0");
1301
+ if (typeof res.flushHeaders === "function") {
1302
+ res.flushHeaders();
1303
+ }
1295
1304
  res.end();
1296
1305
  });
1297
1306
  return;
@@ -1576,7 +1585,14 @@ function safeSendJson(res, statusCode, data) {
1576
1585
  return;
1577
1586
  }
1578
1587
  // Fall back to standard Express methods for real responses
1579
- res.status(statusCode).json(data);
1588
+ res.status(statusCode);
1589
+ // CRITICAL: For Lambda streaming responses, flush headers before send to
1590
+ // initialize the stream wrapper. Check for _responseStream which is unique
1591
+ // to LambdaResponseStreaming (regular Express res doesn't have this).
1592
+ if ("_responseStream" in res && typeof res.flushHeaders === "function") {
1593
+ res.flushHeaders();
1594
+ }
1595
+ res.json(data);
1580
1596
  }
1581
1597
  /**
1582
1598
  * Safely send a response body, avoiding dd-trace interception.
@@ -1604,11 +1620,18 @@ function safeSend(res, statusCode, body) {
1604
1620
  return;
1605
1621
  }
1606
1622
  // Fall back to standard Express methods for real responses
1623
+ res.status(statusCode);
1624
+ // CRITICAL: For Lambda streaming responses, flush headers before send to
1625
+ // initialize the stream wrapper. Check for _responseStream which is unique
1626
+ // to LambdaResponseStreaming (regular Express res doesn't have this).
1627
+ if ("_responseStream" in res && typeof res.flushHeaders === "function") {
1628
+ res.flushHeaders();
1629
+ }
1607
1630
  if (body !== undefined) {
1608
- res.status(statusCode).send(body);
1631
+ res.send(body);
1609
1632
  }
1610
1633
  else {
1611
- res.status(statusCode).send();
1634
+ res.send();
1612
1635
  }
1613
1636
  }
1614
1637
  function expressHandler(handlerOrOptions, optionsOrHandler) {