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