From 693e8d93b0dcb23d9d7fd4a4b799bd5d268b0237 Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Mon, 24 Apr 2023 14:53:13 +0300 Subject: [PATCH] Added URN request generation functionality --- src/anyp/Uri.js | 20 ++++++++++++++++---- src/misc/Global.js | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/anyp/Uri.js b/src/anyp/Uri.js index 29112c5..9bd701f 100644 --- a/src/anyp/Uri.js +++ b/src/anyp/Uri.js @@ -31,6 +31,16 @@ export default class Uri { return this.raw(); } + // makes a unique (XXX: rename) URN URI (RFC 8141) + makeUrn() { + // XXX: If we set this.scheme and keep this.relative false, then + // finalize() will add default authority. Need empty authority?! + this.scheme = "urn"; + this.authority = null; + this.path = "localhost:a123,z456" + UniqueId("/"); + this.relative = true; + } + // call only if you actually need an integer port value; // throws if port is known but malformed // throws if port is unknown and cannot be computed using scheme @@ -58,11 +68,11 @@ export default class Uri { raw() { let image = ""; + if (this.scheme !== null) + image += this.scheme + ":"; if (!this.relative) { - if (this.scheme !== null) - image += this.scheme + "://"; if (this.authority) - image += this.authority.raw(); + image += "//" + this.authority.raw(); } if (this.path !== null) image += this.path; @@ -116,7 +126,9 @@ export default class Uri { } finalize() { - if (!this.relative) { + // XXX: We set these fields even for relative URIs. + // See Client::Transaction::finalizeMessage() + if (true || !this.relative) { if (this.scheme === null) this.scheme = "http"; diff --git a/src/misc/Global.js b/src/misc/Global.js index de7390b..8e0df19 100644 --- a/src/misc/Global.js +++ b/src/misc/Global.js @@ -15,7 +15,8 @@ export function DefaultSchemePort(scheme) { http: 80, https: 443, icap: 1344, - ftp: 21 + ftp: 21, + urn: 80 }; const port = defaultPorts[scheme.toLowerCase()]; Must(port !== undefined);