@adonisjs/http-server 7.2.4 → 7.3.0

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.
@@ -2117,6 +2117,7 @@ var ResponseStatus = {
2117
2117
  };
2118
2118
 
2119
2119
  // src/response.ts
2120
+ import { Buffer as Buffer2 } from "node:buffer";
2120
2121
  import etag from "etag";
2121
2122
  import vary from "vary";
2122
2123
  import fresh2 from "fresh";
@@ -2339,7 +2340,7 @@ var Response = class extends Macroable6 {
2339
2340
  * - Buffer
2340
2341
  */
2341
2342
  #getDataType(content) {
2342
- if (Buffer.isBuffer(content)) {
2343
+ if (Buffer2.isBuffer(content)) {
2343
2344
  return "buffer";
2344
2345
  }
2345
2346
  if (content instanceof Date) {
@@ -2403,7 +2404,8 @@ var Response = class extends Macroable6 {
2403
2404
  this.#endResponse(null, ResponseStatus.NotModified);
2404
2405
  return;
2405
2406
  }
2406
- this.header("Content-Length", Buffer.byteLength(content));
2407
+ this.setRequestId();
2408
+ this.header("Content-Length", Buffer2.byteLength(content));
2407
2409
  if (jsonpCallbackName) {
2408
2410
  this.header("X-Content-Type-Options", "nosniff");
2409
2411
  this.safeHeader("Content-Type", "text/javascript; charset=utf-8");
@@ -2683,6 +2685,17 @@ var Response = class extends Macroable6 {
2683
2685
  this.header("Etag", etag(body, { weak }));
2684
2686
  return this;
2685
2687
  }
2688
+ /**
2689
+ * Set X-Request-Id header by copying the header value from the request if it exists.
2690
+ *
2691
+ */
2692
+ setRequestId() {
2693
+ const requestId = this.request.headers["x-request-id"];
2694
+ if (requestId) {
2695
+ this.header("X-Request-Id", requestId);
2696
+ }
2697
+ return this;
2698
+ }
2686
2699
  /**
2687
2700
  * Returns a boolean telling if the new response etag evaluates same
2688
2701
  * as the request header `if-none-match`. In case of `true`, the
@@ -3766,6 +3779,7 @@ function defineNamedMiddleware(collection) {
3766
3779
 
3767
3780
  // src/router/main.ts
3768
3781
  var Router = class extends LookupStore {
3782
+ #commited = false;
3769
3783
  /**
3770
3784
  * Application is needed to resolve string based controller expressions
3771
3785
  */
@@ -3801,6 +3815,14 @@ var Router = class extends LookupStore {
3801
3815
  * Shortcut methods for commonly used route matchers
3802
3816
  */
3803
3817
  matchers = new RouteMatchers();
3818
+ /**
3819
+ * Check if routes have been committed to the store. Once
3820
+ * routes are committed, defining new set of routes will
3821
+ * have no impact
3822
+ */
3823
+ get commited() {
3824
+ return this.#commited;
3825
+ }
3804
3826
  constructor(app, encryption, qsParser) {
3805
3827
  super(encryption, qsParser);
3806
3828
  this.#app = app;
@@ -3963,6 +3985,10 @@ var Router = class extends LookupStore {
3963
3985
  * commit method is called.
3964
3986
  */
3965
3987
  commit() {
3988
+ if (this.#commited) {
3989
+ return;
3990
+ }
3991
+ debug_default("Committing routes to the routes store");
3966
3992
  const routeNamesByDomain = /* @__PURE__ */ new Map();
3967
3993
  toRoutesJSON(this.routes).forEach((route) => {
3968
3994
  if (!routeNamesByDomain.has(route.domain)) {
@@ -3985,6 +4011,7 @@ var Router = class extends LookupStore {
3985
4011
  this.routes = [];
3986
4012
  this.#globalMatchers = {};
3987
4013
  this.#middleware = [];
4014
+ this.#commited = true;
3988
4015
  }
3989
4016
  /**
3990
4017
  * Find route for a given URL, method and optionally domain
@@ -4198,6 +4225,7 @@ function middlewareHandler(resolver, ctx) {
4198
4225
 
4199
4226
  // src/server/main.ts
4200
4227
  var Server = class {
4228
+ #booted = false;
4201
4229
  /**
4202
4230
  * The default error handler to use
4203
4231
  */
@@ -4271,6 +4299,12 @@ var Server = class {
4271
4299
  this.#resolvedErrorHandler.report(error, ctx);
4272
4300
  return this.#resolvedErrorHandler.handle(error, ctx);
4273
4301
  };
4302
+ /**
4303
+ * Check if the server has already been booted
4304
+ */
4305
+ get booted() {
4306
+ return this.#booted;
4307
+ }
4274
4308
  /**
4275
4309
  * Know if async local storage is enabled or not.
4276
4310
  */
@@ -4369,6 +4403,9 @@ var Server = class {
4369
4403
  * - Resolve and construct the error handler.
4370
4404
  */
4371
4405
  async boot() {
4406
+ if (this.#booted) {
4407
+ return;
4408
+ }
4372
4409
  debug_default("booting HTTP server");
4373
4410
  this.#createServerMiddlewareStack();
4374
4411
  this.#router.commit();
@@ -4379,6 +4416,7 @@ var Server = class {
4379
4416
  const moduleExports = await this.#errorHandler();
4380
4417
  this.#resolvedErrorHandler = await this.#app.container.make(moduleExports.default);
4381
4418
  }
4419
+ this.#booted = true;
4382
4420
  }
4383
4421
  /**
4384
4422
  * Set the HTTP server instance used to listen for requests.
@@ -4524,4 +4562,4 @@ export {
4524
4562
  Server,
4525
4563
  defineConfig
4526
4564
  };
4527
- //# sourceMappingURL=chunk-Q2EOMKJE.js.map
4565
+ //# sourceMappingURL=chunk-2UUPHZPW.js.map