@jaypie/express 1.2.11-dev.4 → 1.2.11-dev.6
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,23 @@ 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
|
+
// Add version header for deployment verification
|
|
860
|
+
headers["x-jaypie-streaming"] = "1.2.11-dev.6";
|
|
861
|
+
// Lambda streaming requires body content for metadata to be transmitted.
|
|
862
|
+
// Convert 204 No Content to 200 OK with empty JSON body as workaround.
|
|
863
|
+
// See: https://github.com/finlaysonstudio/jaypie/issues/178
|
|
864
|
+
let statusCode = this.statusCode;
|
|
865
|
+
if (statusCode === 204) {
|
|
866
|
+
statusCode = 200;
|
|
867
|
+
this._convertedFrom204 = true;
|
|
868
|
+
// Set content-type for the JSON body we'll send
|
|
869
|
+
headers["content-type"] = "application/json";
|
|
870
|
+
}
|
|
858
871
|
const metadata = {
|
|
859
872
|
headers,
|
|
860
|
-
statusCode
|
|
873
|
+
statusCode,
|
|
861
874
|
};
|
|
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
|
|
875
|
+
// Create wrapped stream with metadata
|
|
875
876
|
this._wrappedStream = awslambda.HttpResponseStream.from(this._responseStream, metadata);
|
|
876
877
|
this._headersSent = true;
|
|
877
878
|
// Flush pending writes
|
|
@@ -964,13 +965,14 @@ class LambdaResponseStreaming extends node_stream.Writable {
|
|
|
964
965
|
if (!this._headersSent) {
|
|
965
966
|
this.flushHeaders();
|
|
966
967
|
}
|
|
968
|
+
// For converted 204 responses, write empty JSON body
|
|
969
|
+
// Lambda streaming requires body content for metadata to be transmitted
|
|
970
|
+
if (this._convertedFrom204 && this._wrappedStream) {
|
|
971
|
+
this._wrappedStream.write("{}");
|
|
972
|
+
}
|
|
967
973
|
if (this._wrappedStream) {
|
|
968
974
|
this._wrappedStream.end();
|
|
969
975
|
}
|
|
970
|
-
else {
|
|
971
|
-
// 204 case: headers were written directly, just end the response stream
|
|
972
|
-
this._responseStream.end();
|
|
973
|
-
}
|
|
974
976
|
// Use setImmediate to ensure stream operations complete before callback
|
|
975
977
|
setImmediate(callback);
|
|
976
978
|
}
|