@jaypie/express 1.2.11-dev.4 → 1.2.11-dev.5
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/esm/index.js
CHANGED
|
@@ -652,6 +652,7 @@ class LambdaResponseStreaming extends Writable {
|
|
|
652
652
|
// that need to bypass dd-trace interception
|
|
653
653
|
this._headers = new Map();
|
|
654
654
|
this._headersSent = false;
|
|
655
|
+
this._convertedFrom204 = false;
|
|
655
656
|
this._pendingWrites = [];
|
|
656
657
|
this._wrappedStream = null;
|
|
657
658
|
this._responseStream = responseStream;
|
|
@@ -853,23 +854,21 @@ class LambdaResponseStreaming extends Writable {
|
|
|
853
854
|
for (const [key, value] of this._headers) {
|
|
854
855
|
headers[key] = Array.isArray(value) ? value.join(", ") : String(value);
|
|
855
856
|
}
|
|
857
|
+
// Lambda streaming requires body content for metadata to be transmitted.
|
|
858
|
+
// Convert 204 No Content to 200 OK with empty JSON body as workaround.
|
|
859
|
+
// See: https://github.com/finlaysonstudio/jaypie/issues/178
|
|
860
|
+
let statusCode = this.statusCode;
|
|
861
|
+
if (statusCode === 204) {
|
|
862
|
+
statusCode = 200;
|
|
863
|
+
this._convertedFrom204 = true;
|
|
864
|
+
// Set content-type for the JSON body we'll send
|
|
865
|
+
headers["content-type"] = "application/json";
|
|
866
|
+
}
|
|
856
867
|
const metadata = {
|
|
857
868
|
headers,
|
|
858
|
-
statusCode
|
|
869
|
+
statusCode,
|
|
859
870
|
};
|
|
860
|
-
//
|
|
861
|
-
// Lambda streaming ignores metadata when no body content is written,
|
|
862
|
-
// so we write the prelude manually and skip creating a wrapped stream.
|
|
863
|
-
if (this.statusCode === 204) {
|
|
864
|
-
const prelude = JSON.stringify(metadata);
|
|
865
|
-
this._responseStream.write(prelude);
|
|
866
|
-
// Metadata separator (8 null bytes) signals end of prelude
|
|
867
|
-
this._responseStream.write("\0\0\0\0\0\0\0\0");
|
|
868
|
-
this._headersSent = true;
|
|
869
|
-
// Don't create wrapped stream - 204 has no body
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
// Normal streaming: create wrapped stream
|
|
871
|
+
// Create wrapped stream with metadata
|
|
873
872
|
this._wrappedStream = awslambda.HttpResponseStream.from(this._responseStream, metadata);
|
|
874
873
|
this._headersSent = true;
|
|
875
874
|
// Flush pending writes
|
|
@@ -962,13 +961,14 @@ class LambdaResponseStreaming extends Writable {
|
|
|
962
961
|
if (!this._headersSent) {
|
|
963
962
|
this.flushHeaders();
|
|
964
963
|
}
|
|
964
|
+
// For converted 204 responses, write empty JSON body
|
|
965
|
+
// Lambda streaming requires body content for metadata to be transmitted
|
|
966
|
+
if (this._convertedFrom204 && this._wrappedStream) {
|
|
967
|
+
this._wrappedStream.write("{}");
|
|
968
|
+
}
|
|
965
969
|
if (this._wrappedStream) {
|
|
966
970
|
this._wrappedStream.end();
|
|
967
971
|
}
|
|
968
|
-
else {
|
|
969
|
-
// 204 case: headers were written directly, just end the response stream
|
|
970
|
-
this._responseStream.end();
|
|
971
|
-
}
|
|
972
972
|
// Use setImmediate to ensure stream operations complete before callback
|
|
973
973
|
setImmediate(callback);
|
|
974
974
|
}
|