Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added URN request generation functionality #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/anyp/Uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Expand Down
3 changes: 2 additions & 1 deletion src/misc/Global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down