@jaypie/express 1.2.11 → 1.2.12
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.
- package/dist/cjs/index.cjs +31 -14
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +31 -14
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1613,15 +1613,22 @@ function safeSendJson(res, statusCode, data) {
|
|
|
1613
1613
|
}
|
|
1614
1614
|
// Fall back to standard Express methods for real responses
|
|
1615
1615
|
res.status(statusCode);
|
|
1616
|
-
// CRITICAL: For Lambda streaming responses,
|
|
1617
|
-
// initialize the stream wrapper
|
|
1618
|
-
// before any writes occur (which would auto-flush with default 200).
|
|
1616
|
+
// CRITICAL: For Lambda streaming responses, set content-type BEFORE flushing
|
|
1617
|
+
// headers, then flush to initialize the stream wrapper with all headers.
|
|
1619
1618
|
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1620
|
-
if (isLambdaStreamingResponse(res)
|
|
1621
|
-
|
|
1622
|
-
res.
|
|
1619
|
+
if (isLambdaStreamingResponse(res)) {
|
|
1620
|
+
// Set content-type before flushing so it's included in the metadata
|
|
1621
|
+
res.setHeader("content-type", "application/json");
|
|
1622
|
+
if (typeof res.flushHeaders === "function") {
|
|
1623
|
+
res.flushHeaders();
|
|
1624
|
+
}
|
|
1625
|
+
// Write JSON directly and end the stream (don't call res.json which would
|
|
1626
|
+
// try to set content-type again after headers are already sent)
|
|
1627
|
+
res.end(JSON.stringify(data));
|
|
1628
|
+
}
|
|
1629
|
+
else {
|
|
1630
|
+
res.json(data);
|
|
1623
1631
|
}
|
|
1624
|
-
res.json(data);
|
|
1625
1632
|
}
|
|
1626
1633
|
/**
|
|
1627
1634
|
* Safely send a response body, avoiding dd-trace interception.
|
|
@@ -1653,15 +1660,25 @@ function safeSend(res, statusCode, body) {
|
|
|
1653
1660
|
// initialize the stream wrapper. This ensures the status code is captured
|
|
1654
1661
|
// before any writes occur (which would auto-flush with default 200).
|
|
1655
1662
|
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1656
|
-
if (isLambdaStreamingResponse(res)
|
|
1657
|
-
typeof res.flushHeaders === "function") {
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1663
|
+
if (isLambdaStreamingResponse(res)) {
|
|
1664
|
+
if (typeof res.flushHeaders === "function") {
|
|
1665
|
+
res.flushHeaders();
|
|
1666
|
+
}
|
|
1667
|
+
// Write directly to stream and end (bypass Express send middleware)
|
|
1668
|
+
if (body !== undefined) {
|
|
1669
|
+
res.end(body);
|
|
1670
|
+
}
|
|
1671
|
+
else {
|
|
1672
|
+
res.end();
|
|
1673
|
+
}
|
|
1662
1674
|
}
|
|
1663
1675
|
else {
|
|
1664
|
-
|
|
1676
|
+
if (body !== undefined) {
|
|
1677
|
+
res.send(body);
|
|
1678
|
+
}
|
|
1679
|
+
else {
|
|
1680
|
+
res.send();
|
|
1681
|
+
}
|
|
1665
1682
|
}
|
|
1666
1683
|
}
|
|
1667
1684
|
function expressHandler(handlerOrOptions, optionsOrHandler) {
|