@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/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,23 @@ 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
|
+
// Add version header for deployment verification
|
|
858
|
+
headers["x-jaypie-streaming"] = "1.2.11-dev.6";
|
|
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
|
+
}
|
|
856
869
|
const metadata = {
|
|
857
870
|
headers,
|
|
858
|
-
statusCode
|
|
871
|
+
statusCode,
|
|
859
872
|
};
|
|
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
|
|
873
|
+
// Create wrapped stream with metadata
|
|
873
874
|
this._wrappedStream = awslambda.HttpResponseStream.from(this._responseStream, metadata);
|
|
874
875
|
this._headersSent = true;
|
|
875
876
|
// Flush pending writes
|
|
@@ -962,13 +963,14 @@ class LambdaResponseStreaming extends Writable {
|
|
|
962
963
|
if (!this._headersSent) {
|
|
963
964
|
this.flushHeaders();
|
|
964
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
|
+
}
|
|
965
971
|
if (this._wrappedStream) {
|
|
966
972
|
this._wrappedStream.end();
|
|
967
973
|
}
|
|
968
|
-
else {
|
|
969
|
-
// 204 case: headers were written directly, just end the response stream
|
|
970
|
-
this._responseStream.end();
|
|
971
|
-
}
|
|
972
974
|
// Use setImmediate to ensure stream operations complete before callback
|
|
973
975
|
setImmediate(callback);
|
|
974
976
|
}
|