Why value cannot be used as the base URL, or undefined when it can. The engine
appends every request path to the base URL as a string, so the rules guard the
request URL it builds:
it must parse as an absolute URL with an http: or https: scheme (a file: or
ftp: base URL would otherwise reach a custom transport that does no such check);
no ? or #: either would swallow every path (http://h/?x=1 posts to
/?x=1/STATION_SMALL, http://h/#f to /);
no backslash: WHATWG ends an http(s) host at one, as at a /, while text-based code reads
on, so https://u:pw@a.example\@b.example was checked as a.example and its credentials
could go to b.example;
no surrounding whitespace and no control character anywhere: new URL() trims or
drops them silently, so the URL requested would not be the one typed ("https://h/x "
read as https://h/x, a tab inside a host dropped);
the scheme followed by exactly // and the host (not http:host, http:/host or
http:///host): WHATWG skips any slashes after an http(s) scheme and repairs the URL
silently, so the host requested would not be the one typed either.
The engine requests the base URL as WHATWG parses it (host lower-cased, a default port
dropped, the path percent-encoded where WHATWG does it), the reading every check makes.
Userinfo (user:pw@) is allowed: it is sent as Basic auth and redacted in every
error message. A scheme is named (Unsupported scheme "ftp:") only when the value spells one
(<scheme>://): a user:password@host typed without its scheme parses with the user name as
its scheme. A % in it must start a valid escape (%25 for a literal one), as
Node decodes it for the Authorization header. The reasons never repeat the value, so a credential in it cannot
reach a message. The engine enforces it (Invalid baseUrl: <reason>), and the
CLI's --base-url parser calls it.
Why
valuecannot be used as the base URL, or undefined when it can. The engine appends every request path to the base URL as a string, so the rules guard the request URL it builds:http:orhttps:scheme (afile:orftp:base URL would otherwise reach a custom transport that does no such check);?or#: either would swallow every path (http://h/?x=1posts to/?x=1/STATION_SMALL,http://h/#fto/);/, while text-based code reads on, sohttps://u:pw@a.example\@b.examplewas checked as a.example and its credentials could go to b.example;new URL()trims or drops them silently, so the URL requested would not be the one typed ("https://h/x "read ashttps://h/x, a tab inside a host dropped);//and the host (nothttp:host,http:/hostorhttp:///host): WHATWG skips any slashes after an http(s) scheme and repairs the URL silently, so the host requested would not be the one typed either.The engine requests the base URL as WHATWG parses it (host lower-cased, a default port dropped, the path percent-encoded where WHATWG does it), the reading every check makes.
Userinfo (
user:pw@) is allowed: it is sent as Basic auth and redacted in every error message. A scheme is named (Unsupported scheme "ftp:") only when the value spells one (<scheme>://): auser:password@hosttyped without its scheme parses with the user name as its scheme. A%in it must start a valid escape (%25for a literal one), as Node decodes it for the Authorization header. The reasons never repeat the value, so a credential in it cannot reach a message. The engine enforces it (Invalid baseUrl: <reason>), and the CLI's--base-urlparser calls it.