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