nodeurl

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package nodeurl ports the Node URL host/path handling and fileURLToPath semantics used by PiG.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DomainToUnicode

func DomainToUnicode(host string) string

DomainToUnicode is Node's url.domainToUnicode for a host FileHost returned: an IP address is unchanged, and a domain's IDNA labels become Unicode.

func FileHost

func FileHost(server string) (string, error)

FileHost is the WHATWG host parser's result for a file URL's host: an IPv6 address in brackets, a dotted IPv4 address, or a lowercase ASCII domain, where localhost is empty. The input is percent-decoded first, as the parser does.

func FileURLToPath

func FileURLToPath(raw string, windows bool) (string, error)

FileURLToPath converts raw as Node's url.fileURLToPath(raw, {windows}) does: raw is parsed as a WHATWG URL, and a Windows host names a UNC server in Unicode. It returns the Error Node throws for a URL that does not parse, is not a file URL, encodes a path separator, has a host on POSIX, or on Windows has neither a host nor a drive letter.

func PrepareInput

func PrepareInput(raw string) string

PrepareInput applies the URL parser's C0/space trimming and tab/newline removal.

func RequestURL

func RequestURL(serialized string) (*url.URL, error)

RequestURL represents an already-resolved WHATWG URL without net/url rewriting its serialized spelling. Opaque retains path characters and malformed percent escapes that Go's RawPath cannot represent; Host and Path still identify the request destination.

func ResolveDirectoryPath

func ResolveDirectoryPath(raw, relativePath string) (string, error)

ResolveDirectoryPath resolves a relative URL path beneath a normalized directory base. It applies the WHATWG special-URL authority, host and path rules before resolution; the base query and fragment do not participate in the resulting path.

func SpecialHost

func SpecialHost(server string) (string, error)

SpecialHost parses the host of a WHATWG special URL. Unlike FileHost, localhost remains a hostname.

func SpecialPath

func SpecialPath(pathname string, file bool) string

SpecialPath resolves dot segments in a special URL pathname. File URLs additionally preserve and normalize a leading Windows drive letter.

Types

type Error

type Error struct {
	Code    string
	Message string
}

Error is an error Node's url.fileURLToPath throws, with its code. URIError comes from decodeURIComponent and has no code.

func (*Error) Error

func (e *Error) Error() string

type HTTPURL

type HTTPURL struct {
	Protocol string
	Hostname string
	Port     string
	Search   string
	Hash     string
}

HTTPURL is the part of a WHATWG http or https URL that Node's `new URL(value)` exposes as protocol, hostname, port, search and hash. Search and Hash keep the raw query and fragment after the "?" or "#": the parser's percent-encoding is not applied, so they equal Node's values only in being empty or not.

func ParseHTTPURL

func ParseHTTPURL(raw string) (HTTPURL, error)

ParseHTTPURL is `URL.canParse(raw)` and `new URL(raw)` for an http or https URL without a base. It fails for a URL the parser rejects and for any other scheme, which the callers treat alike: they accept only `http:` and `https:`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL