@jaypie/express 1.2.33 → 1.2.34

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.
@@ -36,6 +36,13 @@ export declare class LambdaResponseBuffered extends Writable {
36
36
  */
37
37
  get headers(): Record<string, string | string[] | undefined>;
38
38
  writeHead(statusCode: number, statusMessageOrHeaders?: OutgoingHttpHeaders | string, headers?: OutgoingHttpHeaders): this;
39
+ /**
40
+ * Node's implicit-header hook, called before the first body byte commits.
41
+ * Routes through this.writeHead resolved at call time so wrappers installed
42
+ * mid-request (on-headers, and through it express-session, morgan,
43
+ * compression, express-openid-connect) run their listeners.
44
+ */
45
+ _implicitHeader(): void;
39
46
  get headersSent(): boolean;
40
47
  /**
41
48
  * Express-style alias for getHeader().
@@ -36,8 +36,16 @@ export declare class LambdaResponseStreaming extends Writable {
36
36
  */
37
37
  get headers(): Record<string, string | string[] | undefined>;
38
38
  writeHead(statusCode: number, statusMessageOrHeaders?: OutgoingHttpHeaders | string, headers?: OutgoingHttpHeaders): this;
39
+ /**
40
+ * Node's implicit-header hook, called before the first body byte commits.
41
+ * Routes through this.writeHead resolved at call time so wrappers installed
42
+ * mid-request (on-headers, and through it express-session, morgan,
43
+ * compression, express-openid-connect) run their listeners.
44
+ */
45
+ _implicitHeader(): void;
39
46
  get headersSent(): boolean;
40
47
  flushHeaders(): void;
48
+ private _commitHeaders;
41
49
  /**
42
50
  * Express-style alias for getHeader().
43
51
  * Used by middleware like decorateResponse that use res.get().
@@ -384,6 +384,7 @@ class LambdaResponseBuffered extends node_stream.Writable {
384
384
  this.getHeaders = this.getHeaders.bind(this);
385
385
  this.getHeaderNames = this.getHeaderNames.bind(this);
386
386
  this.writeHead = this.writeHead.bind(this);
387
+ this._implicitHeader = this._implicitHeader.bind(this);
387
388
  this.get = this.get.bind(this);
388
389
  this.set = this.set.bind(this);
389
390
  this.status = this.status.bind(this);
@@ -540,6 +541,9 @@ class LambdaResponseBuffered extends node_stream.Writable {
540
541
  });
541
542
  }
542
543
  writeHead(statusCode, statusMessageOrHeaders, headers) {
544
+ if (this._headersSent) {
545
+ return this;
546
+ }
543
547
  this.statusCode = statusCode;
544
548
  let headersToSet;
545
549
  if (typeof statusMessageOrHeaders === "string") {
@@ -561,6 +565,17 @@ class LambdaResponseBuffered extends node_stream.Writable {
561
565
  this._headersSent = true;
562
566
  return this;
563
567
  }
568
+ /**
569
+ * Node's implicit-header hook, called before the first body byte commits.
570
+ * Routes through this.writeHead resolved at call time so wrappers installed
571
+ * mid-request (on-headers, and through it express-session, morgan,
572
+ * compression, express-openid-connect) run their listeners.
573
+ */
574
+ _implicitHeader() {
575
+ if (!this._headersSent) {
576
+ this.writeHead(this.statusCode);
577
+ }
578
+ }
564
579
  get headersSent() {
565
580
  return this._headersSent;
566
581
  }
@@ -632,11 +647,13 @@ class LambdaResponseBuffered extends node_stream.Writable {
632
647
  const buffer = Buffer.isBuffer(chunk)
633
648
  ? chunk
634
649
  : Buffer.from(chunk, encoding);
650
+ this._implicitHeader();
635
651
  this._chunks.push(buffer);
636
652
  this._headersSent = true;
637
653
  callback();
638
654
  }
639
655
  _final(callback) {
656
+ this._implicitHeader();
640
657
  this._ended = true;
641
658
  if (this._resolve) {
642
659
  this._resolve(this.buildResult());
@@ -728,6 +745,8 @@ class LambdaResponseStreaming extends node_stream.Writable {
728
745
  this.getHeaderNames = this.getHeaderNames.bind(this);
729
746
  this.writeHead = this.writeHead.bind(this);
730
747
  this.flushHeaders = this.flushHeaders.bind(this);
748
+ this._implicitHeader = this._implicitHeader.bind(this);
749
+ this._commitHeaders = this._commitHeaders.bind(this);
731
750
  this.get = this.get.bind(this);
732
751
  this.set = this.set.bind(this);
733
752
  this.status = this.status.bind(this);
@@ -892,13 +911,27 @@ class LambdaResponseStreaming extends node_stream.Writable {
892
911
  }
893
912
  }
894
913
  }
895
- this.flushHeaders();
914
+ this._commitHeaders();
896
915
  return this;
897
916
  }
917
+ /**
918
+ * Node's implicit-header hook, called before the first body byte commits.
919
+ * Routes through this.writeHead resolved at call time so wrappers installed
920
+ * mid-request (on-headers, and through it express-session, morgan,
921
+ * compression, express-openid-connect) run their listeners.
922
+ */
923
+ _implicitHeader() {
924
+ if (!this._headersSent) {
925
+ this.writeHead(this.statusCode);
926
+ }
927
+ }
898
928
  get headersSent() {
899
929
  return this._headersSent;
900
930
  }
901
931
  flushHeaders() {
932
+ this._implicitHeader();
933
+ }
934
+ _commitHeaders() {
902
935
  if (this._headersSent) {
903
936
  return;
904
937
  }
@@ -1004,7 +1037,7 @@ class LambdaResponseStreaming extends node_stream.Writable {
1004
1037
  // Buffer writes until headers are sent
1005
1038
  this._pendingWrites.push({ callback: () => callback(), chunk: buffer });
1006
1039
  // Auto-flush headers on first write
1007
- this.flushHeaders();
1040
+ this._implicitHeader();
1008
1041
  }
1009
1042
  else {
1010
1043
  this._wrappedStream.write(buffer);
@@ -1012,9 +1045,7 @@ class LambdaResponseStreaming extends node_stream.Writable {
1012
1045
  }
1013
1046
  }
1014
1047
  _final(callback) {
1015
- if (!this._headersSent) {
1016
- this.flushHeaders();
1017
- }
1048
+ this._implicitHeader();
1018
1049
  // For converted 204 responses, write empty JSON body
1019
1050
  // Lambda streaming requires body content for metadata to be transmitted
1020
1051
  if (this._convertedFrom204 && this._wrappedStream) {