@jaypie/express 1.2.11 → 1.2.13
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 +44 -24
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +44 -24
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -53,18 +53,21 @@ class LambdaRequest extends Readable {
|
|
|
53
53
|
remoteAddress: options.remoteAddress,
|
|
54
54
|
};
|
|
55
55
|
this.connection = this.socket;
|
|
56
|
-
// Schedule body push for next tick to ensure stream is ready
|
|
57
|
-
// This is needed for body parsers that consume the stream
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
// Schedule body push for next tick to ensure stream is ready.
|
|
57
|
+
// This is needed for body parsers that consume the stream.
|
|
58
|
+
// CRITICAL: Always schedule the push, even for empty bodies, to ensure
|
|
59
|
+
// the stream emits 'end'. Otherwise, middleware that waits for the request
|
|
60
|
+
// stream to end (like body parsers) will hang forever on GET requests.
|
|
61
|
+
process.nextTick(() => {
|
|
62
|
+
if (!this.bodyPushed) {
|
|
63
|
+
if (this.bodyBuffer && this.bodyBuffer.length > 0) {
|
|
61
64
|
this.push(this.bodyBuffer);
|
|
62
|
-
this.push(null);
|
|
63
|
-
this.bodyPushed = true;
|
|
64
|
-
this.complete = true;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
this.push(null); // Signal end of stream
|
|
67
|
+
this.bodyPushed = true;
|
|
68
|
+
this.complete = true;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
68
71
|
}
|
|
69
72
|
//
|
|
70
73
|
// Readable stream implementation
|
|
@@ -1611,15 +1614,22 @@ function safeSendJson(res, statusCode, data) {
|
|
|
1611
1614
|
}
|
|
1612
1615
|
// Fall back to standard Express methods for real responses
|
|
1613
1616
|
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).
|
|
1617
|
+
// CRITICAL: For Lambda streaming responses, set content-type BEFORE flushing
|
|
1618
|
+
// headers, then flush to initialize the stream wrapper with all headers.
|
|
1617
1619
|
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1618
|
-
if (isLambdaStreamingResponse(res)
|
|
1619
|
-
|
|
1620
|
-
res.
|
|
1620
|
+
if (isLambdaStreamingResponse(res)) {
|
|
1621
|
+
// Set content-type before flushing so it's included in the metadata
|
|
1622
|
+
res.setHeader("content-type", "application/json");
|
|
1623
|
+
if (typeof res.flushHeaders === "function") {
|
|
1624
|
+
res.flushHeaders();
|
|
1625
|
+
}
|
|
1626
|
+
// Write JSON directly and end the stream (don't call res.json which would
|
|
1627
|
+
// try to set content-type again after headers are already sent)
|
|
1628
|
+
res.end(JSON.stringify(data));
|
|
1629
|
+
}
|
|
1630
|
+
else {
|
|
1631
|
+
res.json(data);
|
|
1621
1632
|
}
|
|
1622
|
-
res.json(data);
|
|
1623
1633
|
}
|
|
1624
1634
|
/**
|
|
1625
1635
|
* Safely send a response body, avoiding dd-trace interception.
|
|
@@ -1651,15 +1661,25 @@ function safeSend(res, statusCode, body) {
|
|
|
1651
1661
|
// initialize the stream wrapper. This ensures the status code is captured
|
|
1652
1662
|
// before any writes occur (which would auto-flush with default 200).
|
|
1653
1663
|
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1654
|
-
if (isLambdaStreamingResponse(res)
|
|
1655
|
-
typeof res.flushHeaders === "function") {
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1664
|
+
if (isLambdaStreamingResponse(res)) {
|
|
1665
|
+
if (typeof res.flushHeaders === "function") {
|
|
1666
|
+
res.flushHeaders();
|
|
1667
|
+
}
|
|
1668
|
+
// Write directly to stream and end (bypass Express send middleware)
|
|
1669
|
+
if (body !== undefined) {
|
|
1670
|
+
res.end(body);
|
|
1671
|
+
}
|
|
1672
|
+
else {
|
|
1673
|
+
res.end();
|
|
1674
|
+
}
|
|
1660
1675
|
}
|
|
1661
1676
|
else {
|
|
1662
|
-
|
|
1677
|
+
if (body !== undefined) {
|
|
1678
|
+
res.send(body);
|
|
1679
|
+
}
|
|
1680
|
+
else {
|
|
1681
|
+
res.send();
|
|
1682
|
+
}
|
|
1663
1683
|
}
|
|
1664
1684
|
}
|
|
1665
1685
|
function expressHandler(handlerOrOptions, optionsOrHandler) {
|