wirepath

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wirepath defines the canonical form in which the router compares a request path with registered patterns.

net/http hands the router the path as the client spelled it (net/url.URL.EscapedPath): ASCII, with every byte the client escaped still percent-encoded. RFC 3986 decides which spellings are one URI: an escaped unreserved byte is the literal byte (section 2.3, so "/caf%C3%A9", "/caf%c3%a9" and "/%63af%C3%A9" are the same path and "%2D" is "-"), while an escaped reserved character is a different URI from the literal one (section 2.2, so "%3B" is not ";" and "%2F" is not a segment boundary). The canonical form therefore decodes every escape except those of the reserved characters and of the percent sign itself, which it keeps in upper-case hexadecimal. Registered static text is brought to the same form by escaping its literal percent signs; a decoded capture is then net/url.PathUnescape of the canonical candidate, so a captured "%3B" is the value ";".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CandidateEnd

func CandidateEnd(path string, tail byte) int

CandidateEnd returns the length of the parameter candidate at the start of a canonical path: the text before the first slash or before the first occurrence of tail (the pattern byte after the parameter's closing brace), whichever comes first; a tail of 0 or '/' means the next slash alone. An escape is one unit that is never a boundary: "%2F" is not a slash, "%3B" is not the delimiter ";", and a "%" tail (spelled "%25" in a canonical pattern) is found only as that unit.

func Canonical

func Canonical(escaped string) string

Canonical returns the canonical form of an escaped wire path: every "%XX" escape is replaced by the byte it encodes, except the escapes of the RFC 3986 reserved characters ("/", "?", "#", "[", "]", ":", "@" and the sub-delimiters "!$&'()*+,;=") and of "%", which are normalized to upper-case hexadecimal. A path without escapes is returned as is, without allocating. Malformed escapes (which net/http never forwards) are copied verbatim.

func Escape

func Escape(canonical string) string

Escape returns the wire (escaped) spelling of a canonical path: every byte that may not appear literally in a request path is percent-encoded, while the escapes the canonical form keeps pass through. The result is what net/url.URL.EscapedPath reports for a URL carrying it as RawPath, so a canonical path can be handed to net/http again. A path with nothing to escape is returned as is.

func Static

func Static(text string) string

Static returns the canonical form of literal pattern text: the text as the developer wrote it, with percent signs escaped so that a client's "%25" meets the same bytes. Slashes are pattern separators and stay; every other byte, a reserved character included, matches only its literal spelling.

Types

This section is empty.

Jump to

Keyboard shortcuts

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