request.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.INTERNALS = void 0;
  6. var _nextUrl = require("../next-url");
  7. var _utils = require("../utils");
  8. var _error = require("../error");
  9. var _cookies = require("./cookies");
  10. const INTERNALS = Symbol("internal request");
  11. exports.INTERNALS = INTERNALS;
  12. class NextRequest extends Request {
  13. constructor(input, init = {}){
  14. const url = typeof input !== "string" && "url" in input ? input.url : String(input);
  15. (0, _utils).validateURL(url);
  16. super(url, init);
  17. this[INTERNALS] = {
  18. cookies: new _cookies.NextCookies(this),
  19. geo: init.geo || {},
  20. ip: init.ip,
  21. url: new _nextUrl.NextURL(url, {
  22. headers: (0, _utils).toNodeHeaders(this.headers),
  23. nextConfig: init.nextConfig
  24. })
  25. };
  26. }
  27. [Symbol.for("edge-runtime.inspect.custom")]() {
  28. return {
  29. cookies: this.cookies,
  30. geo: this.geo,
  31. ip: this.ip,
  32. nextUrl: this.nextUrl,
  33. url: this.url,
  34. // rest of props come from Request
  35. bodyUsed: this.bodyUsed,
  36. cache: this.cache,
  37. credentials: this.credentials,
  38. destination: this.destination,
  39. headers: Object.fromEntries(this.headers),
  40. integrity: this.integrity,
  41. keepalive: this.keepalive,
  42. method: this.method,
  43. mode: this.mode,
  44. redirect: this.redirect,
  45. referrer: this.referrer,
  46. referrerPolicy: this.referrerPolicy,
  47. signal: this.signal
  48. };
  49. }
  50. get cookies() {
  51. return this[INTERNALS].cookies;
  52. }
  53. get geo() {
  54. return this[INTERNALS].geo;
  55. }
  56. get ip() {
  57. return this[INTERNALS].ip;
  58. }
  59. get nextUrl() {
  60. return this[INTERNALS].url;
  61. }
  62. /**
  63. * @deprecated
  64. * `page` has been deprecated in favour of `URLPattern`.
  65. * Read more: https://nextjs.org/docs/messages/middleware-request-page
  66. */ get page() {
  67. throw new _error.RemovedPageError();
  68. }
  69. /**
  70. * @deprecated
  71. * `ua` has been removed in favour of \`userAgent\` function.
  72. * Read more: https://nextjs.org/docs/messages/middleware-parse-user-agent
  73. */ get ua() {
  74. throw new _error.RemovedUAError();
  75. }
  76. get url() {
  77. return this[INTERNALS].url.toString();
  78. }
  79. }
  80. exports.NextRequest = NextRequest;
  81. //# sourceMappingURL=request.js.map