From 1b41cd44b5bc3b4f2abec5b27fa809086ae8e5d7 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 10 Aug 2018 21:37:53 -0700 Subject: [PATCH] doc: discuss special protocol handling Fixes: https://github.com/nodejs/node/issues/13523 PR-URL: https://github.com/nodejs/node/pull/22261 Reviewed-By: Rich Trott Reviewed-By: Trivikram Kamat Reviewed-By: Vse Mozhet Byt Reviewed-By: Luigi Pinca Reviewed-By: Jon Moss --- doc/api/url.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/doc/api/url.md b/doc/api/url.md index 64b7b444c54ffd..7a101f6706f36f 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -389,6 +389,46 @@ console.log(myURL.href); Invalid URL protocol values assigned to the `protocol` property are ignored. +##### Special Schemes + +The [WHATWG URL Standard][] considers a handful of URL protocol schemes to be +_special_ in terms of how they are parsed and serialized. When a URL is +parsed using one of these special protocols, the `url.protocol` property +may be changed to another special protocol but cannot be changed to a +non-special protocol, and vice versa. + +For instance, changing from `http` to `https` works: + +```js +const u = new URL('http://example.org'); +u.protocol = 'https'; +console.log(u.href); +// https://example.org +``` + +However, changing from `http` to a hypothetical `fish` protocol does not +because the new protocol is not special. + +```js +const u = new URL('http://example.org'); +u.protocol = 'fish'; +console.log(u.href); +// http://example.org +``` + +Likewise, changing from a non-special protocol to a special protocol is also +not permitted: + +```js +const u = new URL('fish://example.org'); +u.protocol = 'http'; +console.log(u.href); +// fish://example.org +``` + +The protocol schemes considered to be special by the WHATWG URL Standard +include: `ftp`, `file`, `gopher`, `http`, `https`, `ws`, and `wss`. + #### url.search * {string}