@jaypie/express 1.2.11-dev.6 → 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.
@@ -856,8 +856,6 @@ class LambdaResponseStreaming extends node_stream.Writable {
856
856
  for (const [key, value] of this._headers) {
857
857
  headers[key] = Array.isArray(value) ? value.join(", ") : String(value);
858
858
  }
859
- // Add version header for deployment verification
860
- headers["x-jaypie-streaming"] = "1.2.11-dev.6";
861
859
  // Lambda streaming requires body content for metadata to be transmitted.
862
860
  // Convert 204 No Content to 200 OK with empty JSON body as workaround.
863
861
  // See: https://github.com/finlaysonstudio/jaypie/issues/178
@@ -1615,15 +1613,22 @@ function safeSendJson(res, statusCode, data) {
1615
1613
  }
1616
1614
  // Fall back to standard Express methods for real responses
1617
1615
  res.status(statusCode);
1618
- // CRITICAL: For Lambda streaming responses, flush headers before send to
1619
- // initialize the stream wrapper. This ensures the status code is captured
1620
- // 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.
1621
1618
  // Uses Symbol marker for reliable detection that survives prototype manipulation.
1622
- if (isLambdaStreamingResponse(res) &&
1623
- typeof res.flushHeaders === "function") {
1624
- res.flushHeaders();
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);
1625
1631
  }
1626
- res.json(data);
1627
1632
  }
1628
1633
  /**
1629
1634
  * Safely send a response body, avoiding dd-trace interception.
@@ -1655,15 +1660,25 @@ function safeSend(res, statusCode, body) {
1655
1660
  // initialize the stream wrapper. This ensures the status code is captured
1656
1661
  // before any writes occur (which would auto-flush with default 200).
1657
1662
  // Uses Symbol marker for reliable detection that survives prototype manipulation.
1658
- if (isLambdaStreamingResponse(res) &&
1659
- typeof res.flushHeaders === "function") {
1660
- res.flushHeaders();
1661
- }
1662
- if (body !== undefined) {
1663
- res.send(body);
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
+ }
1664
1674
  }
1665
1675
  else {
1666
- res.send();
1676
+ if (body !== undefined) {
1677
+ res.send(body);
1678
+ }
1679
+ else {
1680
+ res.send();
1681
+ }
1667
1682
  }
1668
1683
  }
1669
1684
  function expressHandler(handlerOrOptions, optionsOrHandler) {