@jaypie/express 1.2.4-rc5 → 1.2.4-rc6
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 +61 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +61 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Readable, Writable } from 'node:stream';
|
|
2
|
+
import { ServerResponse } from 'node:http';
|
|
2
3
|
import { CorsError, BadRequestError, UnhandledError, GatewayTimeoutError, UnavailableError, BadGatewayError, InternalError, TeapotError, GoneError, MethodNotAllowedError, NotFoundError, ForbiddenError, UnauthorizedError, NotImplementedError } from '@jaypie/errors';
|
|
3
4
|
import { force, envBoolean, JAYPIE, HTTP, getHeaderFrom, jaypieHandler } from '@jaypie/kit';
|
|
4
5
|
import expressCors from 'cors';
|
|
@@ -159,6 +160,10 @@ function createLambdaRequest(event, context) {
|
|
|
159
160
|
//
|
|
160
161
|
// Constants
|
|
161
162
|
//
|
|
163
|
+
// Get Node's internal kOutHeaders symbol from ServerResponse prototype.
|
|
164
|
+
// This is needed for compatibility with Datadog dd-trace instrumentation,
|
|
165
|
+
// which patches HTTP methods and expects this internal state to exist.
|
|
166
|
+
const kOutHeaders$1 = Object.getOwnPropertySymbols(ServerResponse.prototype).find((s) => s.toString() === "Symbol(kOutHeaders)");
|
|
162
167
|
const BINARY_CONTENT_TYPE_PATTERNS = [
|
|
163
168
|
/^application\/octet-stream$/,
|
|
164
169
|
/^application\/pdf$/,
|
|
@@ -189,6 +194,11 @@ class LambdaResponseBuffered extends Writable {
|
|
|
189
194
|
this._headers = new Map();
|
|
190
195
|
this._headersSent = false;
|
|
191
196
|
this._resolve = null;
|
|
197
|
+
// Initialize Node's internal kOutHeaders for dd-trace compatibility.
|
|
198
|
+
// dd-trace patches HTTP methods and expects this internal state.
|
|
199
|
+
if (kOutHeaders$1) {
|
|
200
|
+
this[kOutHeaders$1] = Object.create(null);
|
|
201
|
+
}
|
|
192
202
|
}
|
|
193
203
|
//
|
|
194
204
|
// Promise-based API for getting final result
|
|
@@ -211,14 +221,31 @@ class LambdaResponseBuffered extends Writable {
|
|
|
211
221
|
// In production, log warning but don't throw to match Express behavior
|
|
212
222
|
return this;
|
|
213
223
|
}
|
|
214
|
-
|
|
224
|
+
const lowerName = name.toLowerCase();
|
|
225
|
+
this._headers.set(lowerName, String(value));
|
|
226
|
+
// Sync with kOutHeaders for dd-trace compatibility
|
|
227
|
+
// Node stores as { 'header-name': ['Header-Name', value] }
|
|
228
|
+
if (kOutHeaders$1) {
|
|
229
|
+
const outHeaders = this[kOutHeaders$1];
|
|
230
|
+
if (outHeaders) {
|
|
231
|
+
outHeaders[lowerName] = [name, String(value)];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
215
234
|
return this;
|
|
216
235
|
}
|
|
217
236
|
getHeader(name) {
|
|
218
237
|
return this._headers.get(name.toLowerCase());
|
|
219
238
|
}
|
|
220
239
|
removeHeader(name) {
|
|
221
|
-
|
|
240
|
+
const lowerName = name.toLowerCase();
|
|
241
|
+
this._headers.delete(lowerName);
|
|
242
|
+
// Sync with kOutHeaders for dd-trace compatibility
|
|
243
|
+
if (kOutHeaders$1) {
|
|
244
|
+
const outHeaders = this[kOutHeaders$1];
|
|
245
|
+
if (outHeaders) {
|
|
246
|
+
delete outHeaders[lowerName];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
222
249
|
}
|
|
223
250
|
getHeaders() {
|
|
224
251
|
const headers = {};
|
|
@@ -412,6 +439,14 @@ class LambdaResponseBuffered extends Writable {
|
|
|
412
439
|
}
|
|
413
440
|
}
|
|
414
441
|
|
|
442
|
+
//
|
|
443
|
+
//
|
|
444
|
+
// Constants
|
|
445
|
+
//
|
|
446
|
+
// Get Node's internal kOutHeaders symbol from ServerResponse prototype.
|
|
447
|
+
// This is needed for compatibility with Datadog dd-trace instrumentation,
|
|
448
|
+
// which patches HTTP methods and expects this internal state to exist.
|
|
449
|
+
const kOutHeaders = Object.getOwnPropertySymbols(ServerResponse.prototype).find((s) => s.toString() === "Symbol(kOutHeaders)");
|
|
415
450
|
//
|
|
416
451
|
//
|
|
417
452
|
// LambdaResponseStreaming Class
|
|
@@ -434,6 +469,11 @@ class LambdaResponseStreaming extends Writable {
|
|
|
434
469
|
this._pendingWrites = [];
|
|
435
470
|
this._wrappedStream = null;
|
|
436
471
|
this._responseStream = responseStream;
|
|
472
|
+
// Initialize Node's internal kOutHeaders for dd-trace compatibility.
|
|
473
|
+
// dd-trace patches HTTP methods and expects this internal state.
|
|
474
|
+
if (kOutHeaders) {
|
|
475
|
+
this[kOutHeaders] = Object.create(null);
|
|
476
|
+
}
|
|
437
477
|
}
|
|
438
478
|
//
|
|
439
479
|
// Header management
|
|
@@ -444,7 +484,16 @@ class LambdaResponseStreaming extends Writable {
|
|
|
444
484
|
// Headers cannot be changed after body starts
|
|
445
485
|
return this;
|
|
446
486
|
}
|
|
447
|
-
|
|
487
|
+
const lowerName = name.toLowerCase();
|
|
488
|
+
this._headers.set(lowerName, String(value));
|
|
489
|
+
// Sync with kOutHeaders for dd-trace compatibility
|
|
490
|
+
// Node stores as { 'header-name': ['Header-Name', value] }
|
|
491
|
+
if (kOutHeaders) {
|
|
492
|
+
const outHeaders = this[kOutHeaders];
|
|
493
|
+
if (outHeaders) {
|
|
494
|
+
outHeaders[lowerName] = [name, String(value)];
|
|
495
|
+
}
|
|
496
|
+
}
|
|
448
497
|
return this;
|
|
449
498
|
}
|
|
450
499
|
getHeader(name) {
|
|
@@ -452,7 +501,15 @@ class LambdaResponseStreaming extends Writable {
|
|
|
452
501
|
}
|
|
453
502
|
removeHeader(name) {
|
|
454
503
|
if (!this._headersSent) {
|
|
455
|
-
|
|
504
|
+
const lowerName = name.toLowerCase();
|
|
505
|
+
this._headers.delete(lowerName);
|
|
506
|
+
// Sync with kOutHeaders for dd-trace compatibility
|
|
507
|
+
if (kOutHeaders) {
|
|
508
|
+
const outHeaders = this[kOutHeaders];
|
|
509
|
+
if (outHeaders) {
|
|
510
|
+
delete outHeaders[lowerName];
|
|
511
|
+
}
|
|
512
|
+
}
|
|
456
513
|
}
|
|
457
514
|
}
|
|
458
515
|
getHeaders() {
|